私はMSVisualStudio2010を使用しています。
二重リンクリストを実装しました。
オブジェクトのデストラクタを呼び出すメソッドCleanを呼び出した後のメイン関数で、オブジェクトを参照した後、エラーが発生しないのはなぜだろうか。
これが私の二重リンクリストメソッドのいくつかです(私の質問に関連して):
/*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標準で述べられているように、オブジェクトはもう存在しません*、なぜデストラクタが呼び出された後もオブジェクトを使用できるのですか?