About Store Forum Documentation Contact
Donations:
206$/mo



Post Reply 
Static array, inconsistent behaviour.
Author Message
Tottel Offline
Member

Post: #1
Static array, inconsistent behaviour.
Hi,

I have a static array (vRes) in my GraphicsOptions class.

Code:
static Vec2 vRes[]=
   {
      Vec2(1366,  768),
      Vec2(1440,  900),
      Vec2(1920, 1080),
      Vec2(1920, 1200),
   };

If I want to do operations on this from a different class, like:

Code:
int elms = ELMS(GraphicOptions.vRes);


it gives me a compiler error: "error C2070: 'EE:Vec2 []': illegal size of operand".

But, if I move this static array into the class that I call the operation from, I can do this without any problems:

Code:
int elms = ELMS(vRes);


Same thing happens with Iterations.
Any idea why?

Thanks!
08-25-2015 02:32 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: Static array, inconsistent behaviour.
my guess the code editor is unable to place the elms after the array is defined maybe?
(This post was last modified: 08-25-2015 04:42 PM by Zervox.)
08-25-2015 04:42 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Static array, inconsistent behaviour.
only this "static Vec2 vRes[];" will be in the header file, from which it is impossible to know the number of elements in the array.
The solution is to do:
Code:
static Vec2 vRes[]=
   {
      Vec2(1366,  768),
      Vec2(1440,  900),
      Vec2(1920, 1080),
      Vec2(1920, 1200),
   };
static int vResElms=Elms(vRes);
and use 'vResElms' everywhere.

Alternatively you can ditch the array and use a memory container like Mems for example.

Or you can specify the number of elements:
Code:
static Vec2 vRes[4]= // <-4 here
   {
      Vec2(1366,  768),
      Vec2(1440,  900),
      Vec2(1920, 1080),
      Vec2(1920, 1200),
   };
but that is risky in case you set the number wrong in relation to actual number of elements.
08-26-2015 03:33 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #4
RE: Static array, inconsistent behaviour.
Thanks guys!

To be honest, I improved my class design so I no longer need this kind of behaviour. I was just wondering why this was happening. smile
08-26-2015 08:08 AM
Find all posts by this user Quote this message in a reply
Post Reply