#ifndef PERSON_H
#define PERSON_H
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class Person
{
private:
string firstname;
string lastname;
public:
virtual void Show() const;
Person():firstname(“none”),lastname(“none”) {};
Person(const string &fn,const string &ln):firstname(fn),lastname(ln) {};
Person(const char *fn,const char *ln):firstname(fn),lastname(ln) {};
~Person(){};
};
class Gunslinger:virtual public Person
{
private:
int num;
int time;
public:
double Draw(){return time;}
void Show() const;
Gunslinger():num(0),time(0),Person(){}
Gunslinger(const int n,const int t) :num(n),time(t),Person(){}
Gunslinger(const int n,const int t,const string &firstname,const string &lastname)
:num(n),time(t),Person(firstname,lastname){}
~Gunslinger(){};
protected:
void PShow() const;
};
class PikerPlayer:virtual public Person
{
private:
int value;
public:
int Draw(){srand(time(0));return rand()%52;}
PikerPlayer():value(0),Person(){}
PikerPlayer(const int v):value(v),Person(){}
PikerPlayer(const int v,const string &firstname,const string &lastname)
:value(v),Person(firstname,lastname){}
~PikerPlayer(){}
void Show() const;
protected:
void PShow() const;
};
class BadDude : public Gunslinger,public PikerPlayer
{
public:
double Gdraw();
int Cdraw();
void Show();
BadDude():Person(),PikerPlayer(),Gunslinger(){}
BadDude(const int n,const int t,const int v,const string &firstname,const string &lastname)
:Person(firstname,lastname),PikerPlayer(v),Gunslinger(n,t){}
~BadDude(){}
};
#endif
error C2250: “BadDude”:“void Person::Show(void) const”的不明确继承,求指导SOS
#define PERSON_H
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class Person
{
private:
string firstname;
string lastname;
public:
virtual void Show() const;
Person():firstname(“none”),lastname(“none”) {};
Person(const string &fn,const string &ln):firstname(fn),lastname(ln) {};
Person(const char *fn,const char *ln):firstname(fn),lastname(ln) {};
~Person(){};
};
class Gunslinger:virtual public Person
{
private:
int num;
int time;
public:
double Draw(){return time;}
void Show() const;
Gunslinger():num(0),time(0),Person(){}
Gunslinger(const int n,const int t) :num(n),time(t),Person(){}
Gunslinger(const int n,const int t,const string &firstname,const string &lastname)
:num(n),time(t),Person(firstname,lastname){}
~Gunslinger(){};
protected:
void PShow() const;
};
class PikerPlayer:virtual public Person
{
private:
int value;
public:
int Draw(){srand(time(0));return rand()%52;}
PikerPlayer():value(0),Person(){}
PikerPlayer(const int v):value(v),Person(){}
PikerPlayer(const int v,const string &firstname,const string &lastname)
:value(v),Person(firstname,lastname){}
~PikerPlayer(){}
void Show() const;
protected:
void PShow() const;
};
class BadDude : public Gunslinger,public PikerPlayer
{
public:
double Gdraw();
int Cdraw();
void Show();
BadDude():Person(),PikerPlayer(),Gunslinger(){}
BadDude(const int n,const int t,const int v,const string &firstname,const string &lastname)
:Person(firstname,lastname),PikerPlayer(v),Gunslinger(n,t){}
~BadDude(){}
};
#endif
error C2250: “BadDude”:“void Person::Show(void) const”的不明确继承,求指导SOS
解决方案
5
你基类里声明的都是void Show() const,你BadDude里写的是void Show()。
60
是原因是两个基类都含有show(),不知道从哪个继承吧?
10
BadDude 类中的
void Show();
改成:
void Show() const;
void Show();
改成:
void Show() const;