Deleting TreeViewItem


I want to delete (remove) selected item from TreeView on demand (for example, when the item is clicked). Is this the safe way to do it - i am not sure because i am deleting item inside item’s member function. Code is working ok, though (am not refering to deleted item anymore).

Any other suggestion or hint would be great !!!

void N4TreeViewItem::itemClicked (const MouseEvent& e)
  myTreeViewPointer->getSelectedItem (0)->getParentItem()->removeSubItem (0);


I have a few instances, mainly related to tree view type things, where objects have to delete themselves. Never feels hugely comfortable or sane, but I think is just fine if you don’t reference any data the object holds after the delete…