Enemy_Scouts = new CEnemy[MAX_ENEMY_SCOUT];
for (int i = 0; i < MAX_ENEMY_SCOUT; i++)
{
Enemy_Scouts[i]->SetHealth(100); //100 hp for each enemy scout by default
}
and the error i got was "error C2440: '=' : cannot convert from 'CEnemy *' to 'CEnemy *[3]'"
I thought i was doing it right? What can i do to make the array of pointers? Cause I dont want to use do array of objects.
And since my intellisense works(eg. when i type "Enemy_Scouts[i]->" the members of the class shows up while when i type "Enemy_Scouts[i]. "the members of the class do not show up ), i figured it should work
I thought i was doing it right? What can i do to make the array of pointers? Cause I dont want to use do array of objects.
Enemy_Scoutsis an array of pointers. It shouldn't be defined in a header file, but that doesn't contribute to the current problem you're experiencing.
This: Enemy_Scouts = new CEnemy[MAX_ENEMY_SCOUT]; attempts to set your array equal to a pointer. It's an array of pointers. It is not, itself, a pointer.
The pointers in the array don't point to valid memory of course. That's the job you need to accomplish. If each pointer is supposed to point to 1 CEnemy, you might do the following:
1 2
for (unsigned i=0; i<MAX_ENEMY_SCOUT; ++i)
Enemy_Scouts[i] = new EnemyScout ;
Of course, this isn't very C++ish code with the raw pointers and manual memory management.
for (int i = 0; i < MAX_ENEMY_SCOUT; i++)
{
Enemy_Scouts[i] = new CEnemy();
Enemy_Scouts[i]->SetHealth(100); //100 hp
}
but i still have the same error. the error "error C2440: '=' : cannot convert from 'CEnemy *' to 'CEnemy *[3]' " seems to point to Enemy_Scouts = new CEnemy[MAX_ENEMY_SCOUT];
Is the statement Enemy_Scouts = new CEnemy[MAX_ENEMY_SCOUT]; valid? Cause I do want to make a pointer of arrays with each element pointing to a CEnemy