虚基类函数的不明确继承

C++语言 码拜 7年前 (2017-04-19) 2471次浏览
#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
解决方案

5

你基类里声明的都是void Show() const,你BadDude里写的是void Show()。

60

是原因是两个基类都含有show(),不知道从哪个继承吧?

10

BadDude 类中的
void Show();
改成:
void Show() const;

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明虚基类函数的不明确继承
喜欢 (0)
[1034331897@qq.com]
分享 (0)