20140802 虚函数
1、虚函数
http://blog.csdn.net/livelylittlefish/article/details/2171504
2、面试宝典
#include<iostream> using namespace std; class A { protected: int m_data; public: A(int data=0) {m_data=data; cout<<"构造函数A"<<endl; } int Getdata() {return doGetdata(); } virtual int doGetdata() { cout<<m_data<<endl; return m_data;} }; class B: public A { protected: int m_data; public: B(int data=1) {m_data=data; cout<<"构造函数B"<<endl;} int Getdata() { return doGetdata(); } virtual int doGetdata() { cout<<m_data<<endl; return m_data; } }; class C: public B { protected: int m_data; public: C(int data=2) {m_data=data; cout<<"构造函数C"<<endl; } }; int main() { C c(10); c.Getdata(); c.A::Getdata(); c.B::Getdata(); c.C::Getdata(); c.doGetdata(); c.A::doGetdata(); c.B::doGetdata(); c.C::doGetdata(); system("pause"); return 0; }