欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

虚基类继承时虚函数的重写问题?

程序员文章站 2022-05-14 13:08:48
...
#include<string>
#include<ctime>
class Person   // an abstract base class
{
private:
	std::string firstname;
	std::string lastname;
protected:
	virtual void Data();
	virtual void Get();
public:
	Person() : firstname("no firstname"), lastname("no lastname") {}
	Person(const std::string& s1, const std::string& s2)
		: firstname(s1), lastname(s2) {}
	virtual ~Person() {} // pure virtual function

	virtual void Show();
	virtual void Set();
};

class Gunslinger :virtual public Person {
private:
	double gun_time;
	int nickings;
protected:
	virtual void Data();
	virtual void Get();
	double Draw() { return gun_time; }
public:
	Gunslinger() :Person(), gun_time(0.0), nickings(0) {}
	Gunslinger(const std::string& s1, const std::string& s2, double gt, int n)
		:Person(s1, s2), gun_time(gt), nickings(n) {}
	Gunslinger(const Person& p, double gt, int n)
		:Person(p), gun_time(gt), nickings(n) {}
	~Gunslinger() {}
	
	virtual void Show();
	virtual void Set();
};
/*class Card {
private:
	enum { spades, diamonds, clubs, hearts };
public:
	Card()
};*/


class PokerPlayer :virtual public Person {
protected:
	virtual void Data() ;
	virtual void Get();
	int Draw();
public:
	PokerPlayer() :Person() {}
	PokerPlayer(const std::string& s1, const std::string& s2)
		:Person(s1, s2){}
	~PokerPlayer() {}
	virtual void Show();
	virtual void Set();
};



class BadDude : public Gunslinger, public PokerPlayer
{

public:
	BadDude() : Person(), Gunslinger(), PokerPlayer() {}
	BadDude(const std::string& fn, const std::string& ln, int ct = 0, double t = 0)
		: Person(), Gunslinger(fn, ln, ct, t), PokerPlayer() {}
	BadDude(const Person& ps, int ct = 0, double t = 0) 
		: Gunslinger(ps, ct, t), PokerPlayer() {}
	BadDude(const Gunslinger& gs) 
		: Person(gs), PokerPlayer() {}
	BadDude(const PokerPlayer& pp, int ct = 0, double t = 0) 
		: Person(pp), Gunslinger(pp, ct, t) {}
	~BadDude() {}
	void Set();
	void Show();
};

出现E0318,
虚拟函数 函数Person::Data重写不明确,是什么地方出错了呢。。。