c_model::~c_model(){ //delete the model data if it hasn't already happened if (!hasThisMemoryBeenDeletedAlready(m_vtx)) delete [] m_vtx; if (!hasThisMemoryBeenDeletedAlready(m_vtx)) delete [] m_nrm; if (!hasThisMemoryBeenDeletedAlready(m_vtx)) delete [] m_uvw; if (!hasThisMemoryBeenDeletedAlready(m_vtx)) delete [] m_tri; return;}
Instead there are techniques to solve this problem, the most common of which I listed in my first reply. My reply was aimed at situations where multiple objects could own a single pointer, since this is the most common situation to your problem.
Next you stated that this was not the situation you were dealing with and that the data was entirely contained within your class. For this case since data should be allocated exactly once and deallocated exactly once it makes sense to put the allocation and deallocation code into functions that can only legally be called once, the constructor and destructor. You simply should not be suffering double deallocation problems with this.
At this point you seemed to favour a technique which I consider dangerous. While it may be sufficient in your case it is brittle in others. I posted an example of such a situation, showing that wrapped pointers are safer. I was going to post an example based on exception safety, which you may have issues with in your case, but did not want to overcomplicate the matter.
The point is that if you follow my suggestions and allocate in the constructor/deallocate in the destructor or wrap your pointers your code will work and will require minimal work to keep safe if you modify it. The setting pointers to null method on the other hand may cause you significant problems later on if you discover the need to make your model objects copyable.
I'm sorry if either of my posts seemed rude, I was simply finding it difficult to comprehend what your exact problem was. I think I now understand that you were doing i.e.:
class Model{ public: Model() { array_ = new int[3]; } ~Model() { if (!array_) { delete[] array_; } } void kill() { delete[] array_; } private: int * array_;};int main(){ Model model; model.kill();}
All you are doing here is adding unneccessary work with the kill function. Follow RAII (allocate in the constructor, deallocate in the destructor) and/or wrap your pointers. Trust me, it will lead to safer, more robust code.
Enigma