-
Array of Struct??
I can't seem to figure out how to make an array of a user defined struct. I define my struct, like so:
Code:
struct MYSTRUCT {
float x;
const char *Name;
};
The i try to allocate an array like this:
Code:
MYSTRUCT MyStruct1 = new MYSTRUCT[ 24 ];
Several errors come up and I don't know what to do. I am also trying to define an array of structs/unions inside of another struct the same way... error also occurs there. HELP????
-
I'm not sure, since I haven't programmed in C for a short while, but how about this:
struct MYSTRUCT MyStruct1[24];
???
-
This is C++ not C... and the problem with that is that i have to allocate the array when i declare the variable and i dont want to do that...
-
riis thing should work without "struct" before it. If you want to have an array of unknown/variable length then you use a dynamic array, in your example MyStruct1* instead of MyStruct1. Easiest would be to use vector from STL: vector<MYSTRUCT> MyStruct1;
-
It should be:
Code:
MYSTRUCT* MyStruct1 = new MYSTRUCT[ 24 ];
You forgot to make the MyStruct1 a pointer variable. Remember to delete [] MyStruct1 when you are done. If you want to declare a standard array of MYSTRUCT, the syntax is:
Code:
MYSTRUCT MyStruct1[24];
Z.