我使用 MS Visual Studio 2010。
我实现了一个双链表。
我想知道为什么在调用方法 Clean 之后的 main 函数中,它调用对象的析构函数,在我引用对象之后没有引发错误。
这是我的一些双链表方法(相对于我的问题):
/*DoubleLinkedList.cpp */
DoubleLinkedList::~DoubleLinkedList(void)
{
cout << "Destructor invoked" << endl;
// as for data nodes memory is allocated in heap we have to release it:
const Node* const_iterator = m_head.m_next;
while (const_iterator != &m_tail)
{
const_iterator = const_iterator->m_next;
delete const_iterator->m_prev;
}
}
void DoubleLinkedList::Clean(void)
{
cout << "Clean invoked" << endl;
this->~DoubleLinkedList(); /* According to C++ 11 standart: Once a destructor is invoked for an object, the object no longer exists*/
}
/* main.cpp */
int main(int argc, char* argv[])
{
DoubleLinkedList list;
Circle c1, c2(MyPoint(1,1),50), c3(MyPoint(2,2),30);
list.Front(&c1);
list.Front(&c2);
list.Front(&c3);
list.Show();
list.Sort();
list.Show();
list.Clean();
list.Show(); /* Recall how Clean method is implemented. As list no longer exist, run-time error is expected here, but flow of executon continues and Show, Push_back preforms fine*/
list.Push_back(&c1);
list.Push_back(&c2);
list.Push_back(&c3);
问题: *如调用析构函数后的 C++ 11 标准中所述 - 对象不再存在*,为什么在调用析构函数后我仍然能够使用该对象?