<分区>
#include<stdio.h>
class test2
{
public:
void testFunc()
{
printf("test");
}
test2(){}
~test2(){}
};
class test1 : test2
{
public:
test1(){
link = new test2();}
~test1(){
delete link;
link = NULL;
}
test2* link = NULL;
private:
};
int main()
{
test1 *ptr = new test1();
delete ptr;
ptr->link->testFunc();
return 0;
}
我想在调用 test1 的析构函数后删除 test2 对象。然而,在调用 delete 并将链接设置为 NULL 之后,我仍然能够调用成员函数“testFunc”并使用链接指针打印“test”。 为什么这是可能的?