Hello, for my final team project for C++ we are making a simple space invaders clone with the SDL libraries.
Most of it is working great so far but in order to 'destroy' the enemies, they must not be drawn anymore and should be destructed.

ER is just the # of rows, same with EC - columns
Now the problem I'm having is when checking if(!enemies[r][c]==NULL)
which tells me:
error C2676: binary '==' : 'Enemy' does not define this operator or a conversion to a type acceptable to the predefined operator

// Show new enemy locations
for(int r=0; r<ER; r++)
	for(int c=0; c<EC; c++)
		// Shows each enemy at their specific locations

I figured that maybe I might have to try and overload the == operator but I'm not even sure if that's the right step nor do I know how to do it properly.

Any help appreciated, thanks.

8 Years
Discussion Span
Last Post by BigTito89

IIRC enemies is 2d array of Enemy. To compare in this way, you need to declare array of pointers to Enemy(dirty solution), initialized to null. Of course you need to remember to delete every not needed enemy etc and change every function, which use enemies. You can also make state variable in Enemy class, indicating whether this enemy is alive, or dead.
I would do this using std::map <coordinates,Enemy> where coordinates store r and c and has operator< overloaded, this way you will only store and use enemies who are alive.


Zjarek, thanks for the input but it seems the problem was simple than I thought. I took your advice for a state variable and compared that and modified the code accordingly. Didn't have to use a map nor the Enemy* idea.

But thank you anyway!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.