A-A+
下面程序的结果是 #include<iostream.h> class A { int a;
问题详情
下面程序的结果是 #include<iostream.h> class A { int a; public: A():a(1){} void showa(){cout<<a;} }; class B { int a; public: B() :a(2) {} void showa(){cout<<a;} }; class C:public A,public B { int a; public: C():a(3){} void showa(){cout<<a;} }; void main() { C c; c.showa(); }
A.1
B.2
C.3
D.程序有错误请帮忙给出正确答案和分析,谢谢!
参考答案
正确答案:C
解析:类A,类B,中都有showa()函数,类C继承后再次重写showa()函数就解决了继承的二义性,这时c.showa()函数显示的就是类C中的showa()的值。