Abbreviation: deleting a template pointer does not call the destructor.
includes solves the problem. Why?
I just ran into a situation that I cannot explain. I am trying to break a more difficult situation here.
R.cpp file
class R {
Owner<Problem> m_o;
void cleanUp() { m_o.clear(); }
}
Owner.cpp file
struct DeleteFunctor {
template< class TPtr > void operator()(TPtr* ptr) { delete ptr; }
};
template< class T >
class Owner {
std::vector<T*> m_objects;
void clear() {
std::for_each( m_objects.begin(), m_objects.end(), DeleteFunctor() );
m_objects.clear();
}
Now I have a utility class that creates new problem objects on the heap and inserts them directly into m_o. I know this is a bad style for exporting references to internal types, but it is not.
If I call cleanUp (), I can trace it to calling delete ptr in Functor, with ptr having the correct type of problem. But the destructor problem is not called !!
However, including the problem header in the R.cpp file, this problem resolves the problem. The compiler does not complain. Is this a compiler error?
:
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2