📄 example1-17.cpp
字号:
#include <iostream.h>
class Baseclass
{
public:
Baseclass()
{
a=0;
}
Baseclass(int i)
{
a=i;
}
void Baseprint()
{
cout<<"a is :"<<a<<" ";
}
~Baseclass()
{
cout<<"The baseclass destructed"<<endl;
}
private:
int a;
};
class Derivedclass:public Baseclass
{
public:
Derivedclass()
{
b1=0;
b2=0;
}
Derivedclass(int b)
{
b1=0;
b2=b;
}
Derivedclass(int j,int k,int l) //在此构造函数中,显示调用了基类的构造函数
{
Baseclass::Baseclass(j);
b1=k;
b2=l;
}
void Derivedprint()
{
Baseclass::Baseprint();
cout<<"b1 is :"<<b1<<" "<<"b2 is :"<<b2<< endl;
}
~Derivedclass()
{
cout<<"The Derivedclass destructed"<<endl;
}
private:
int b1,b2;
};
void main()
{
Derivedclass B1;
Derivedclass B2(10);
Derivedclass B3(5,6,7);
B1.Derivedprint();
B2.Derivedprint();
B3.Derivedprint();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -