📄 类的继承问题.cpp
字号:
#include <iostream.h>
class CBase
{
public:
CBase()
{
myintdata=new int[50];
cout<<"CBase::Constructor,allocating 50 integers!"<<endl;
}
~CBase()
{
if(myintdata)
{
delete[] myintdata;
cout<<"CBase::Destructor,deallocating 50 integers!"<<endl;
}
}
protected:
int * myintdata;
};
class CDerived:public CBase
{
public:
CDerived()
{
myfloatdata=new float[50];
cout<<"CDerived::Constructor,allocating 50 floating numbers !"<<endl;
}
~CDerived()
{
if(myfloatdata)
{
delete[] myfloatdata;
cout<<"CDerived::Destructor,deallocating 50 floating numbers !"<<endl;
}
}
protected:
float * myfloatdata;
};
class CDerivedDerived:public CDerived
{
public:
CDerivedDerived()
{
mydoubledata=new double[50];
cout<<"CDerivedDerived::Constructor,allocating 50 double floating numbers !"<<endl;
}
~CDerivedDerived()
{
if(mydoubledata)
{
delete[] mydoubledata;
cout<<"CDerivedDerived::Destructor,deallocating 50 double floating numbers !"<<endl;
}
}
protected:
double * mydoubledata;
};
void main()
{
CDerivedDerived myobject;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -