class FHello_F{};
//
class FTestA :public FHello_F
{
//构造函数一定在public
public:
FTestA();
FTestA(const FTestA &Test);
FTestA(int Ina, int intb, int inc);
//析构函数
~FTestA();
public:
int a;
int b;
int c;
FTest3* T3;
};
FTestA::FTestA()
{
this->a = 11;
this->b = 13;
this->c = 9;
this->T3 = new FTest3();
}
//初始化列表,变量需要按顺序初始化,也可以初始化父类构造
FTestA::FTestA(int Ina, int intb, int inc)
:FHello_F()
,a(Ina)
,b(intb)
,c(inc)
{
T3 = new FTest3();
}
FTestA::FTestA(const FTestA& Test)
{
this->a = Test.a;
this->b = Test.b;
this->T3 = new FTest3();
*this->T3 = *Test.T3;
}
//释放
FTestA::~FTestA()
{
if (T3)
{
delete T3;
T3 = nullptr;
}
}
C++ 笔记 构造函数、析构函数、初始化列表
于 2024-08-18 10:32:25 首次发布