example1-17.cpp

来自「关于书籍《Borland c++Builder工程实践》的源代码」· C++ 代码 · 共 64 行

CPP
64
字号
#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 + =
减小字号Ctrl + -
显示快捷键?