c++派生类继承两个基类,两基类中有重复的变量名,编译器报错,应如何处理? 10
代码如下:#include<iostream>usingnamespacestd;classa{public:intnum;};classb{public:charch;...
代码如下:
#include <iostream>
using namespace std;
class a
{
public:
int num;
};
class b
{
public:
char ch;
int num;
};
class c: public a, public b
{
};
int main()
{
c test;
test.num = 1;
test.ch = 'a';
cout << test.num << test.ch <<endl;
return 0;
}
编译器报错信息:
error: request for member 'num' is ambiguous 展开
#include <iostream>
using namespace std;
class a
{
public:
int num;
};
class b
{
public:
char ch;
int num;
};
class c: public a, public b
{
};
int main()
{
c test;
test.num = 1;
test.ch = 'a';
cout << test.num << test.ch <<endl;
return 0;
}
编译器报错信息:
error: request for member 'num' is ambiguous 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询