1

C++ (Arduino wrapper) question: This is related to this thread on double pointer member access regarding a shoot em up game.

I have a base class (Sprite), and from this other classes are derived - Alien and Player. For collision detection I want to pass pointers to Alien and Player, then access coordinates as in:

void Collision( Alien *pAlien, Player *pPlayer )
{
  // obtain alien and player's (x,y) and do collision check here
  pAlien->getX();
  pPlayer->getX();
}

But after declaring the above function after the class I get this:

error: variable or field 'Collision' declared void

My question is: How can I resolve this? streamlined code and a screen shot are shown below.

/*****************************************************************************************/
// Bass class - has a form/shape, x and y position also has a method of moving  
class Sprite
{
  public:
    Sprite(unsigned char * const spacePtrIn, unsigned int xInit, unsigned int yInit);
  protected:  
};

/*****************************************************************************************/
// Derived class "Alien" - has a specific form/shape, and specific (x,y) position
class Alien : public Sprite
{
public:
   Alien(); 
   virtual void Move();
};

/*****************************************************************************************/
// Derived class "Player" - has a specific form/shape, and specific (x,y) position
class Player : public Sprite
{
public:
   Player(): Sprite(&spaceShip[0], xPlayer(), yPlayer()) {}
   virtual void Move(); 
};


/*****************************************************************************************/
/*****************************************************************************************/
void Collision( Alien *pAlien, Player *pPlayer )
{
  // obtain alien and player's (x,y) and do collision check here
  pAlien->getX();
  pPlayer->getX();
}
/*****************************************************************************************/

/*****************************************************************************************/

enter image description here

Community
  • 1
  • 1
Harry Lime
  • 2,167
  • 8
  • 31
  • 53
  • 2
    Is the Collision function part of a class? If it's a function in the global scope I believe you would have to forward declare the function prototype, or define the entire function before the other class definitions. If it's part of a class like Player, then you should use scope resolution like you did with Move. – TheSecretSquad Dec 29 '13 at 02:18
  • thanks for the reply - no, collision(stuff) is not part of a class; its in global scope. Though I'm unsure, I think I need to a header file and then include this - is this what you mean? My ref: http://stackoverflow.com/questions/17493354/arduino-struct-pointer-as-function-parameter – Harry Lime Dec 29 '13 at 02:25

0 Answers0