【发布时间】:2022-01-03 08:39:44
【问题描述】:
我正在尝试重载 std::cout << player2; 我得到“0x7f60b0100”作为输出。
“player2”是一个 Actor*,所以我不确定发生了什么。
class Actor {
private:
string type;
protected:
int health;
int damage;
vector<MoveType> moves;
public:
Actor(string type, int health): type{ type }, health{ health }{damage=0;}
virtual void Hit(int damage){health = health-damage;}
virtual void Heal(int amount){health=+amount;}
const vector<MoveType>& GetMoves() const {return moves;}
bool IsDead() { return health <= 0; }
friend ostream& operator<<(ostream& out, const Actor& actor){
return (out << "DAMAGE DONE: " << actor.damage << "HEALTH: "<< actor.health);
}
};
【问题讨论】:
标签: c++11