64,652
社区成员
发帖
与我相关
我的任务
分享
class Role
{
public:
virtual int attack() = 0;
virtual int defend() = 0;
virtual int hit() = 0;
}
class Player : public Role
{
public:
Player();
Player(string name, char hp, char att, char def, char lv) : strName(name), chHP(hp), chAttack(att), chDefence(def), chLevel(lv) {}
int attack(Player);
int defend(Player);
int hit(Player);
int getHP();
int setModifyHP(int);
private:
string strName;
char chHP;
char chAttack;
char chDefence;
char chLevel;
};
class Role
{
public:
virtual int attack(Role&) = 0;
virtual int defend(Role&) = 0;
virtual int hit(Role&) = 0;
}
Player &p1 = (Player &)p2
编译的时候就会提示错误,Xcode返回错误:
Undefined symbols for architecture x86_64:
"Player::getDefence()", referenced from:
Player::attack(Role&) in main.o
Player::attack(Role&) in Game.o
"Player::getHP()", referenced from:
Player::attack(Role&) in main.o
_main in main.o
Player::attack(Role&) in Game.o
"Player::setHP(int)", referenced from:
Player::attack(Role&) in main.o
Player::hit(Role&) in main.o
Player::attack(Role&) in Game.o
Player::hit(Role&) in Game.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
g++返回错误和上面那个一样。
class Role
{
public:
virtual int attack(Role&) = 0;
virtual int defend() = 0;
virtual int hit(Role&) = 0;
};
class Player : public Role
{
public:
Player();
Player(string name, char hp, char att, char def, char lv) : strName(name), chHP(hp), chAttack(att), chDefence(def), chLevel(lv) {}
int attack(Player&);
int defend();
int hit(Player&);
int getHP();
int getAttack();
int getDefence();
int setHP(int);
private:
string strName;
char chHP;
char chAttack;
char chDefence;
char chLevel;
bool isDefend;
};
不是说如果继承抽象类的类没有重写抽象类的抽象方法,那这个类也是抽象类,我这个是不是这种问题?