#include<iostream> using namespace std; class A { public: int n; }; class B:public A {}; // class B:virtual public A{}; class C:public A {}; // class C:virtual public A{}; class D:public B,public C { public: int getn() {return B::n;} }; int main() { D d; d.B::n=10; d.C::n=20; cout<<d.getn()<<endl; return 0; }
(1)程序执行后,运行结果是多少?
(2)将程序中有注释的两条语句修改为注释的内容,即将“class B:public A {};”修改为“class B:virtual public A{};”,“class C:public A {}; ”修改为“class C:virtual public A{};”,重新编译运行程序,程序的运行结果又是多少?
原文地址:http://blog.csdn.net/ljd939952281/article/details/45949905