I created a class that has as members two pointers to other classes I created. I am having problems with the destructor of this class. Because the members are pointers, I try to use delete in the destructor, but the error does not go away. I already tried not to do anything in the destructor.
Because the members are pointers, I try to use delete in the destructor
Are these pointers you try to delete created with new? If not, you should not delete them. Another problem could be that you delete these pointers twice in your program...
EDIT: In genaral, when you use aggregation (i.e. composition with pointers), the containing class is not responsible for the creation/destruction of the contained objects.
The members that are pointers are declared in the header file and created with new in the constructor of the composition class.
The objects that are pointed should not exist after the composition class has been destroyed and that is one of the reasons why I try to delete them, otherwise they will be lost somewhere, right? (You are right, in a pure aggregation objects can still exist.)
I never use delete except in the destructor of the composition class. But actually the mistake I have seems that something is being freed twice and that is a bad mistake!
It would be a good idea to, but if you are only using your constructor to create instances, you could go ahead and make the = and copy constructor private (so they can't be called).
Anyway, your issue is you are NULLing the pointers before you are deleting them.
As a general rule, if you have to free memory in your destructor either with delete or free(), then
you need to write an appropriate copy constructor and assignment operator, otherwise you have
to make the class non-copyable (declare copy constructor and assignment operator in the private
section and leave them unimplemented).