一个面试题,该怎么解决
一个面试题
class A
{
public:
int n;
};
class B:public A
{
};
class C:public A
{
};
class D:public B,public C
{
};
void main()
{
D d;
d.B::n = 10;
d.C::n = 20;
cout << d.A::n << d.C::n << endl;
//cout << d.D::n << endl;
system("pause");
}
d.A::n输出多少
当时问我输出什么,我说这个存在二义性,要报错。人家说我错了,会输出,大家帮忙分析分析。。。。。。
------解决方案--------------------
楼主没错。
VC2010报C2385错。
这样的单位最好别去。你对,可是管事的人不是你,你跟他们扯不清的。。。混的时间久了,看问题会产生偏差。
class A
{
public:
int n;
};
class B:public A
{
};
class C:public A
{
};
class D:public B,public C
{
};
void main()
{
D d;
d.B::n = 10;
d.C::n = 20;
cout << d.A::n << d.C::n << endl;
//cout << d.D::n << endl;
system("pause");
}
d.A::n输出多少
当时问我输出什么,我说这个存在二义性,要报错。人家说我错了,会输出,大家帮忙分析分析。。。。。。
面试题
C++
------解决方案--------------------
楼主没错。
VC2010报C2385错。
这样的单位最好别去。你对,可是管事的人不是你,你跟他们扯不清的。。。混的时间久了,看问题会产生偏差。