繁星淼淼
下面分析两个经典面试题。l 例1:class A{protected:int m_data;public:A(int data = 0){m_data = data;}int GetData(){return doGetData();}virtual int doGetData(){return m_data;}};class B: public A{protected : int m_data;public:B(int data = 1){m_data = data;}int doGetData(){return m_data;}};class C : public B{protected : int m_data;public :C(int data = 2){m_data = data;}};int _tmain(int argc, _TCHAR* argv[]){C c(10);cout<<c.GetData() << endl; //1cout<<c.A::GetData()<<endl; //1cout<<c.B::GetData()<<endl; //1cout<<c.C::GetData()<<endl; //1cout<<c.doGetData()<<endl; //1cout<<c.A::doGetData()<<endl; //0cout<<c.B::doGetData()<<endl; //1cout<<c.C::doGetData()<<endl; //1return 0;}