/*烟台大学计算机学院学生
*All right reserved.
*文件名称:体验派生类和积累之间的赋值
*作者:杨飞
*完成日期:2014年4月15日
*版本号:v1.0
*对任务及求解方法的描述部分:体验派生类和积累之间的赋值
*我的程序:*/
#include <iostream>
using namespace std;
class A
{
protected:
int a,b;
public:
A(int aa,int bb)
{
a=aa;
b=bb;
}
void display()
{
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
}
};
class B:public A
{
private:
int c;
public:
B(int aa,int bb,int cc):A(aa,bb),c(cc){}
void show()
{
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
}
};
int main()
{
A a(1,1);
B b(2,3,4);
a.display();
b.show();
cout<<"将b赋值给a"<<endl;
a=b;
a.display();
return 0;
}
运行结果:
心得体会:加油