#include<iostream>
using namespace std;
class base{
int a,b;
public:
void set_ab(int x,int y){this->a=x;b=y;}
void show(){cout<<"a and b is "<<a<<"/t"<<b<<endl;}
};
class derived:public base{
int c;
public:
void set_c(int x){c=x;}
void show_c(){cout<<"c is "<<c<<endl;}
};
int main()
{
derived cl;
base *p;
cl.set_ab(1,2);
cl.set_c(3);
p=&cl;
p->show();
return 0;
}
测试结果:
a and b is 1 2
Press any key to continue