作者:好开心6327 | 来源:互联网 | 2024-10-11 10:32
AssumeIhaveastructurewithtwopointerseachpointingtoanobjectthathasanimplementeddestr
Assume I have a structure with two pointers each pointing to an object that has an implemented destructor. Also assume that the head points to a Listnode structure that has a non-NULL value *student and *next:
假设我有一个带有两个指针的结构,每个指针指向一个具有已实现的析构函数的对象。还假设头指向Listnode结构,该结构具有非NULL值* student和* next:
struct Listnode {
Student *student;
Listnode *next;
};
Listnode *head = new Listnode;
If I use the delete
reserve word on the Listnode pointer 'head' will it call the destructors within that structures Student class and Listnode class which 'student' and 'next' point-to respectively. In other words, will deleting *head also delete *student and *next provided head was the only pointer to that Listnode
如果我在Listnode指针'head'上使用删除保留字,它将调用该结构中的析构函数Student class和Listnode类,其中'student'和'next'分别指向。换句话说,将删除* head也删除* student和* next提供的head是唯一指向该Listnode的指针
2 个解决方案