C++ C++;(Arduino包装器):声明为void Arduino的变量或字段

C++ C++;(Arduino包装器):声明为void Arduino的变量或字段,c++,object,pointers,collision-detection,C++,Object,Pointers,Collision Detection,C++(Arduino包装器)问题:这与关于射击游戏的这个线程有关 我有一个基类(精灵),从这个基类派生出其他类-外星人和玩家。对于碰撞检测,我希望将指针传递给Alien和Player,然后访问坐标,如中所示: void Collision( Alien *pAlien, Player *pPlayer ) { // obtain alien and player's (x,y) and do collision check here pAlien->getX(); pPlay

C++(Arduino包装器)问题:这与关于射击游戏的这个线程有关

我有一个基类(精灵),从这个基类派生出其他类-外星人和玩家。对于碰撞检测,我希望将指针传递给Alien和Player,然后访问坐标,如中所示:

void Collision( Alien *pAlien, Player *pPlayer )
{
  // obtain alien and player's (x,y) and do collision check here
  pAlien->getX();
  pPlayer->getX();
}
但在类之后声明上述函数后,我得到:

错误:变量或字段“冲突”声明为无效

我的问题是:我如何解决这个问题?简化的代码和屏幕截图如下所示

/*****************************************************************************************/
// 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();
}
/*****************************************************************************************/
/*****************************************************************************************/


碰撞功能是类的一部分吗?如果它是全局范围内的函数,我相信您必须向前声明函数原型,或者在其他类定义之前定义整个函数。如果它是类的一部分,比如Player,那么你应该像使用Move一样使用范围解析;它在全球范围内。虽然我不确定,我想我需要一个头文件,然后包括这个-这是你的意思吗?我的裁判: