问题及代码:
/*
*copyright(c) 2016烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:杨昊
*版本:v6.0
*
*问题描述: 训练1-5
*输入描述:无
*程序输出:
*/
#include <iostream>
using namespace std;
class A
{
protected:
int a,b;
public:
A(int aa, int bb):a(aa), b(bb) {}
void printA(){
cout<<"a: "<<a<<"\tb: "<<b<<endl;
}
};
class B: public A
{
int c;
public:
B(int aa, int bb, int cc):A(aa,bb),c(cc) {}
void printB()
{
cout<<"a: "<<a<<"\tb: "<<b<<"\tc: "<<c<<endl;
}
};
int main()
{
A a(1,1);
B b(2,3,4);
a=b;
a.printA();
b.printA();
b.printB();
return 0;
}
结果及总结: