One of possible solutions is to do reference counting on "E" and copy it by value (with a shared reference counter of course) between those objects that use it. Or if you use Qt, QSharedPointer is the thing you want to use (if you don't but you use C++ you can use boost/std::shared_ptr). And for clarity E should be created outside B to avoid doubts related to ownership of E (since E can live longer than B if it is shared with another object). As for now you are trying to access an already deleted object.
Bookmarks