Somewhere in my code I call: A* p = new A; and I put the pointer p in a vector.
Now I want to delete the pointer and the class the pointer is pointing to. like this:
A* p = getpointerfromvector(index); // gets the correct pointer
Delete the pointer from the vector:
vector.erase(vector.begin()+index)
Now I want to delete the class the pointer is pointing to and delete it.
delete p; // (doest work: memorydump)
or p->~A with ~A the destructor of class A with body: delete this;. (my program quits whenever I call the function.)
Ais the name of a class, whilepis a pointer to an object. When you donew Ayou are creating a new object, not a new class. It is important to keep the notions of class and object separate :)delete pis correct. If it doesn't work, post an sscce demonstrating the problem.