Tottel
Member
|
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 |
|
Zervox
Member
|
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 |
|
Esenthel
Administrator
|
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 |
|
Tottel
Member
|
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.
|
|
08-26-2015 08:08 AM |
|