My program crashes upon exit. Tracing the error back I arrived at the destructor of the class gWSW. Here is the problem:
I have a class gShop: public gTexture. In this class I declare and initializes a pointer to an object of the class gWSW.
In gWSW I have again a pointer to an object declared and initialized of the class gTexture.
I have given every class the proper destructor with calling delete on the pointers.
The programm runs fine until I press ESC and all the desctuctors are called. Here it crashes in the destructor of gWSW. That is I have something like that:
class gShop : public gTexture
{
public:
gShop(): pWSW(new gWSW()) {}
~gShop(){delete pWSW;}
gWSW* pWSW;
};
class gWSW
{
public:
gWSW():gWSW: pTextuer(new gTexture()) {}
~gWSW(){delete pTexture;}
gTexture* pTexture;
};
class gTexture
{
public:
gTexture() {}
~gTexture();
//... a pointer to char[] here but will be also deleted in its destructor
};
The last call before crashing is in ~gWSW(). Commenting "delete pTexture" out makes the program exit fine without errors or crashes. Before I continue and leaving it commented, I like to understand what the problem is please.