#include
using namespace std;
class Base1
{
public:
char c;
};
class Base2
{
public:
int c;
};
class Derived: public Base1, public Base2
{
public:
void show() { cout << c; }
};
int main(void)
{
Derived d;
d.show();
return 0;
}
(A) “ cout << c;”中的编译器错误
(B)垃圾价值
(C) “派生类:public Base1,public Base2”中的编译器错误答案: (A)
说明:变量’c’在Derived的两个超类中都存在。因此,访问“ c”是模棱两可的。可以使用范围解析运算符消除歧义。
#include
using namespace std;
class Base1
{
public:
char c;
};
class Base2
{
public:
int c;
};
class Derived: public Base1, public Base2
{
public:
void show() { cout << Base2::c; }
};
int main(void)
{
Derived d;
d.show();
return 0;
}
这个问题的测验
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。