I want to make an pointer array of objects. Is this right?
Is this right?Code:*Enemy = new Enemy_1[4];
Cheers
I want to make an pointer array of objects. Is this right?
Is this right?Code:*Enemy = new Enemy_1[4];
Cheers
Enemy is a pointer to an array (of 4) objects of type Enemy_1
> Is this right?
It's what you've got.
Whether it's what you want is another matter.
If you want an array of pointers to objects, then you're way off.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
>>Enemy is a pointer to an array (of 4) objects of type Enemy_1
yup yup. THats what i want. just double checking that the syntax is right!
thx
I'm concerned with the lhs of the statement as originally posted. In particular--How is Enemy declared?
For example, if Enemy is defined like this:
Enemy_1 * Enemy;
followed by the line that is posted, then I think there is a problem. On the other hand, if the statement posted is a typo for this:
Enemy_1 * Enemy = new Enemy_1[4];
then everything looks in order. And if Enemy is declared some other way, then who knows without seeing it.
Well.....It's declared as such:
Then I use it...Code:Enemy_1 *Enemy = new Enemy_1[4];
and I get this erorr...Code:i=0; for(i=0;i<5;i++) { Enemy[i]->Enemy1_Sprite->Picture->LoadFromFile("ship-5.bmp"); }
So i changed the declaration to...Code:[C++ Error] Lvl1.h(20): E2288 Pointer to structure required on left side of -> or ->*
Which version is right?Code:*Enemy = new Enemy_1[4];
Thx for the help!
Try:Enemy_1 is an array of objects. You access an object's data using '.', so when you want to access the data of the object at index i (using [i]), you have to change the '->' to '.'.Code:Enemy_1 *Enemy = new Enemy_1[4]; for(i=0;i<5;i++) { Enemy[i].Enemy1_Sprite->Picture->LoadFromFile("ship-5.bmp"); }