C++ 类的继承

来源:互联网 发布:五毛钱特效app软件 编辑:程序博客网 时间:2024/05/22 12:58
# include <iostream>using namespace std;class Base{public:Base(int x=0) :a(1){}virtual void show(){cout<<"Base cout"<<endl;}private:int a;};class Derive : public Base{public:Derive(int y=0) :b(3){}void show(){cout<<"Derive cout"<<endl;}private:int b;};int main(){ Base *m; Derive *n; m = new Derive; n = new Derive; m->show(); n->show(); cout<<sizeof(Base)<<endl; cout<<sizeof(Derive)<<endl;return 0;}

原创粉丝点击