为什么当我试图通过这样的一个指针创建一个属性到另一个类我收到一个错误:指向另一个类的属性
#ifndef SQUARE_H
#define SQUARE_H
#include <string>
//using namespace std;
#include "Player.h"
class Square
{
public:
Square(int);
void process();
protected:
int ID;
Player* PlayerOn; <---
};
#endif
和Player类是:
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
//using namespace std;
#include "Square.h"
class Player
{
public:
Player(int,int);
// ~Player(void);
int playDice();
private:
int ID;
int money;
};
#endif
我收到:
syntax error missing ; before * (on the declaration of Player* PlayerOn;)
和缺少类型说明符(在同一行...)
您的文章伤害了我的眼睛,您是否可以将每个文件的代码放入代码块中,而不是将它们分成几个? –
为什么你在Player.h中包含Square.h? – Mark
@标记这是他错误的原因(由于#ifdef),你可能想把它放在答案:) –