Hi all
I have a
std::vector <T*> vec in my code. I'm adding stuff to this vector using
vec.push_back( new T )
Once I want to remove the content from the program, I use
delete vec.back();
vec.pop_back();
For some reason, this method is not calling the destructor on whatever I'm deleting... Below is the exact code from the project:
// m_state_stack is the std::vector <R2e::State*>
template <class T>
void
R2e::Engine::
changeState()
{
// Make sure the new state is derived from R2e::State
BOOST_STATIC_ASSERT(( boost::is_base_of <R2e::State, T>::value ));
if ( !m_state_stack.empty() ) {
delete m_state_stack.back();
m_state_stack.pop_back();
}
m_state_stack.push_back( new T );
m_state_stack.back()->init( this );
}
template <class T>
void
R2e::Engine::
pushState()
{
// Make sure the new state is derived from R2e::State
BOOST_STATIC_ASSERT(( boost::is_base_of <R2e::State, T>::value ));
if ( !m_state_stack.empty() )
m_state_stack.back()->pause();
m_state_stack.push_back( new T );
m_state_stack.back()->init( this );
}
void
R2e::Engine::
popState()
{
if ( !m_state_stack.empty() ) {
delete m_state_stack.back();
m_state_stack.pop_back();
}
if ( !m_state_stack.empty() )
m_state_stack.back()->resume();
}
How come that the destructor isn't called on objects once I call delete on the back of the vector?