I have a project with vtk, in which a lot of vtk objects are constructed as private members. At .h files I initialize vtk objects like below:
vtkSmoothPolyDataFilter *m_SmoothFilter;
vtkDecimatePro *m_DecimatePro;
vtkCleanPolyData *m_CleanPolyData;
During runtime, some of these objects are initialized with New() command, but some of them not. Since I can't use smart pointers (due to the incapability with my UI package) I have to delete these objects at the destructor. I have to use some boolean checking system to understand whether they are initialized:
if(m_SmoothFilter)
m_SmoothFilter->Delete()
if(m_DecimatePro)
m_DecimatePro->Delete()
But this code excerpt doesn't detect whether the objects are initialized. How can I do this check?
Initialize all of your pointers to zero or an actual object that has been created with new. Then your C++ delete can delete without any ifs (it's ok to delete a zero pointer). I'm not sure what your Delete() above does.