How do I know if it was properly deleted?īy knowing when your program has deleted it, and making sure you don't use any dangling pointers afterwards. In short, dereferencing a pointer to a deleted object gives undefined behaviour. If you're very lucky, the memory might have been unmapped, and you'll get a friendly segmentation fault to point out the error, but that typically only happens with very large objects. If you still have a pointer to the memory that contained the object, you might or might not be able to access its remnants or perhaps another, unrelated object that has been created since the object was deleted. Why can still access class instances after deleting them? Just wanted to point that out to avoid any confusion.įorgive me if I was vague or otherwise unclear with this post, but I'm not very skilled when it comes to asking questions online. There are a couple of variables here ( position2df vector2df ) that come from the Irrlicht Game Engine. I guess the ultimate question is: am I doing something wrong? If I can still access the instance members after I deleted it how do I know if it was properly deleted? I suppose at this point a question is in order :D the previous class instance's Node::Node *nextNode.I don't know if it matters, but the instance has three different pointers pointing to it at the time of its deletion. However, even after deleting it I can still access the instance and output its members. In the NodeList::Node *pop() function (whose purpose is to delete the last element and reset the previous one as the end of the list), I call delete on the Node class instance pointed by (pointer name) slider. / Function for removing objects from the list.įor(previous=NULL next!=NULL next=slider->nextNode)Ĭout << "Can still access deleted object: " << (*slider).getID() << endl / Function for adding elements to the list. So I'm building a a linked list class, with stack-like functionality (LIFO), to hold instances of a Node class: enum Sides
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |