例如,假设您有:
Class Test
{
public:
Test();
private:
int x = 0;
int y = 3;
}
您使用类似的东西声明一个 Test 实例
Test * RRR = new Test();
假设在您键入的行的某个地方
delete RRR;
这是否也会删除 x 和 y 占用的内存?
例如,假设您有:
Class Test
{
public:
Test();
private:
int x = 0;
int y = 3;
}
您使用类似的东西声明一个 Test 实例
Test * RRR = new Test();
假设在您键入的行的某个地方
delete RRR;
这是否也会删除 x 和 y 占用的内存?
the short answer is yes, but strictly speaking, x and y are not deleted. The memory they tak will be released, because they are data members of the struct.
Even you don't define a destructor, the compiler will synthesized a default destructor for you, which will release the memory that the struct takes.