64,682
社区成员
发帖
与我相关
我的任务
分享
/*************************************************************************
> File Name: cthread.cpp
> Author: Jukay
> Mail: hellojukay@gmail.com
> Created Time: 2014年10月27日 星期一 16时24分41秒
************************************************************************/
#include<iostream>
#include<string>
using namespace std;
class CBase
{
public:
string id;
};
class CDeriva1 : public CBase
{
public:
void show1()
{
cout<< "CDerival: " << id << endl;
}
};
class CDeriva2 : public CBase
{
public:
void show2()
{
cout<< "CDerival2: " << id << endl;
}
};
class CSon : public CDeriva2, public CDeriva1 {}
int main()
{
CSon s;
s.CDeriva1::id = "wd8503026";
s.CDeriva2::id = "wd8503027";
s.CBase::id = "wd8503025";
s.show1();
s.show2();
cout<< "BASE: " << s.CBase::id << endl;
return 0;
}
请按 ENTER 或其它命令继续
cthread.cpp: In function ‘int main()’:
cthread.cpp:44:11: error: ‘CBase’ is an ambiguous base of ‘CSon’
s.CBase::id = "wd8503025";
^
cthread.cpp:47:30: error: ‘CBase’ is an ambiguous base of ‘CSon’
cout<< "BASE: " << s.CBase::id << endl;
^
Shell 已返回1
#include<iostream>
#include<string>
using namespace std;
class CBase
{
public:
string id;
};
class CDeriva1 : virtual public CBase /*virtual */
{
public:
void show1()
{
cout<< "CDerival: " << id << endl;
}
};
class CDeriva2 : virtual public CBase /*virtual */
{
public:
void show2()
{
cout<< "CDerival2: " << id << endl;
}
};
class CSon : public CDeriva2, public CDeriva1 {}; /* ; */
int main()
{
CSon s;
s.CDeriva1::id = "wd8503026";
s.CDeriva2::id = "wd8503027";
s.CBase::id = "wd8503025";
s.show1();
s.show2();
cout<< "BASE: " << s.CBase::id << endl;
return 0;
}
请按 ENTER 或其它命令继续
cthread.cpp:28:1: error: expected class-name before ‘{’ token
{
^
cthread.cpp: In member function ‘void CDeriva2::show2()’:
cthread.cpp:32:28: error: ‘id’ was not declared in this scope
cout<< "CDerival2: " << id << endl;
^
cthread.cpp: In function ‘int main()’:
cthread.cpp:43:14: error: ‘class CDeriva2’ has no member named ‘id’
s.CDeriva2::id = "wd8503027";
^
Shell 已返回1