Hey guys while working on a new crappy game I have stumbled across a problem. I am trying to use a template for a overloaded == in my class for collision. I am not good with words here is the code
character.h
character.cppCode:#ifndef character_h #define character_h #include <allegro.h> class character { public: character(); character(int x, int y, const char *image1, const char *image2); template <class T> bool operator ==(T &obj);//handle collisions BITMAP *retImage() const;//returns current image /************************************************************************* Decided to make these variables public because they would be accessed alot and functions to get and set them would be a waste **************************************************************************/ int xPos;//character's x coord for drawing int yPos;//character's y coord for drawing int currentImage;//to hold currrent image for switching image for movement int left;//left coord for collision int right;//right coord for collision int top;//top coord for collision int bottom;//bottom coord for collision private: BITMAP *image[2];//The characters image have two for "animation" }; #endif
All seems to be well with this but when I go to use it in my code for some detection I get an unresolved linker error. Its just a simple if statement eg.Code:template <class T> bool character::operator==(T &obj) { return !(right < obj.left||obj.right < left||bottom < obj.top||obj.bottom < top); }
Is there some way that I need to be handling the enemy. I know with templates and functions that you would do an <type> before you would call it but that doesn't seem reasonable here.Code:if(player == enemy) { //do stuff }



LinkBack URL
About LinkBacks



.