|
-
Apr 8th, 2002, 02:29 PM
#1
Thread Starter
Addicted Member
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????
To protect time is to protect everything...
-
Apr 8th, 2002, 02:42 PM
#2
Fanatic Member
I'm not sure, since I haven't programmed in C for a short while, but how about this:
struct MYSTRUCT MyStruct1[24];
???
-
Apr 8th, 2002, 03:26 PM
#3
Thread Starter
Addicted Member
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...
To protect time is to protect everything...
-
Apr 8th, 2002, 04:16 PM
#4
transcendental analytic
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;
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 8th, 2002, 10:27 PM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|