Language: Cpp
Compiler: MS Visual Studio.NET
I just jump right into my question. Say we have this template struct:
template <typename T>
struct SFoo {
T s_tfoo_data; // Holds the foo data
// holds the origin of where the foo data comes from
std::vector< char* > s_hFooOrigin;
// inline fuction that clears the foo origin vector
inline void ClearFooOrigin() { s_hFooOrigin.clear(); }
};
Now say that we have template class:
template <typename T>
class CFoo {
public:
// Default Constructor that sets the vector to NULL;
CFoo() { m_hFooVector = NULL; }
// Deconstructor
~CFoo()
private:
// This is a vector of the SFoo<T> pointers that holds all the foo objects
vector< SFoo<T>* > m_hFooVector;
};
My question is how would the deconstructor for the CFoo class look.
What I thought it should look like, this that I should traverse through the vector m_hFooVector calling the ClearFooOrigin() function, then setting that to NULL and deleteing it.
// PseudoCode
~CFoo() {
std::vector< SFoo<T>* >::iterator itr
for(itr = m_hFooVector.begin(); itr != m_hFooVector.end(); itr++) {
(*itr)->ClearFooOrigin();
(*itr) = NULL;
delete (*itr);
}
}
Is the deconstructor code going to free the memory used by the vector m_hFooVector? Or am I doing it wrong? I'm trying to stop a memory leak from happening by not free but the memory used by the vector.
Thank you ahead of time for anyone that helps = ]