c++ 关于继承 关于虚函数
class Base{ Base(); ~Base(); virtual foo(){cout<<"Base::foo"<<endl;}}class Derive :public Base{ Derive(){foo();}; ~Derive(); foo(){cout<<"Derive::foo"<<endl;}void main(){ Derive b;}#include <iostream>using namespace std;class Base{public: Base() { foo(); // 这里也增加一个调用 } virtual ~Base(){} virtual void foo() { cout << "Base::foo" << endl; }};class Derive :public Base{public: Derive() { foo(); } ~Derive(){} void foo() { cout << "Derive::foo" << endl; }};int main(int argc, char* argv[]){ Derive b; return 0;}