-
Array Help
Hey, I'm kind of new at c++ and I have a question about arrays. Can you make any type of object an array? I tried and I don't know if i did it wrong or if my idea is too farfetched or what...
Example:
Code:
class Cpart{
/*blah blah blah*\
};
Cpart cow;
Cpart IDtoPart[15];
IDtoPart[0] = cow;
Like i said, I really need some help here. Anything is greatly appreciated. Thanks!
-
What you have should work, but you don't need to assign cow to IDtoPart[0], just initialize IDtoPart[0] since it is a valid object:
Code:
class Obj
{
public:
int i;
};
int main()
{
Obj array[10];
array[0].i = 10;
return 0;
}
Note that some operations will be more difficult or finicky if you don't have the appropriate constructors defined for the class.
-Prelude
-
Haven't tried it yet but i'm sure it will work. Its not exactly what I wanted but it will work. That will help me out a lot... thanks!