#include<iostream> using namespace std; class my_base { int a,b; public: my_base(int x,int y) { a=x; b=y; } virtual void show() { cout<<"base"; cout<<a<<" "<<b<<endl; } }; class my_class: public my_base { int c; public: my_class(int x,int y,int z):my_base(x,y) { c=z; } void show() { cout<<"my_class "<<"c="<<c; } }; int main() { my_base mb(50,50),*mp; my_class mc(10,20,30); mp=&mb; mp->show(); mp=&mc; mp->show(); return 0; }
运行结果:
时间: 2024-11-08 06:13:55