I'm sure I'm doing something wrong but I'm relatively new to boost's shared_ptr and I saw some issues when using the EventManager from the book.
If I created dynamic memory for a class that implements the IEventListener interface. When I subscribe to any event using the pointer to that object that was created I can't clean up the memory myself at game end without getting an error. Seems boost cleans up the memory for that object for me.
For example:
EventListenerPtr Listener( m_pGameManager );
EventManager::Instance()->RegisterListener( Listener, EventType(PlayActionBegin::s_strName));
Now m_pGameManager was created by me earlier. If I call delete m_pGameManager then I get an exception. If I don't its destructor is called when the EventManager goes away.
Any ideas what I may be doing wrong?
EDIT - Ok I did some web checking on boost::shared_ptr and found a codeproject writeup on using them correctly. I need to internalize it more, though. Looks like the .get() method allows me to pass the native type pointer to functions. I need to pass CGameManager* around in some places.
Steve
If I created dynamic memory for a class that implements the IEventListener interface. When I subscribe to any event using the pointer to that object that was created I can't clean up the memory myself at game end without getting an error. Seems boost cleans up the memory for that object for me.
For example:
EventListenerPtr Listener( m_pGameManager );
EventManager::Instance()->RegisterListener( Listener, EventType(PlayActionBegin::s_strName));
Now m_pGameManager was created by me earlier. If I call delete m_pGameManager then I get an exception. If I don't its destructor is called when the EventManager goes away.
Any ideas what I may be doing wrong?
EDIT - Ok I did some web checking on boost::shared_ptr and found a codeproject writeup on using them correctly. I need to internalize it more, though. Looks like the .get() method allows me to pass the native type pointer to functions. I need to pass CGameManager* around in some places.
Steve
Steve Jones
The post was edited 1 time, last by smjones ().