In C++ I've got a
class A which has an abstract class pointer to permit polymorphism found in a
class B, I've another pointer for an abstract
class C that allocates a concrete demonstration of a young child class of
class B into that memory and I have to call a cleanup (see question below) function from
class C to deallocate the memory taken through the child class of
class B which i allotted in the heap, the issue is I can not guarantee I have the cleanup function because I have only a pointer to
class C that we can't just copy, because it may be gone when I call have to destroy the that contains
To be able to solve the issue of not getting accessibility cleanup function can one call remove around the
class A pointer despite the fact that I am pointing to some child class? Does C++ new also store heap block size like malloc to ensure that you can easily remove memory recommended with a pointer for an abstract class such as this? Otherwise can there be a different way to organize this program that enables me to handle situation?
I am using my very ball since it is strict your question however, you most likely need virtual destructors.
The conventional states (§5.3.5 ¶3):
Within the first alternative (remove object), when the static kind of the operand differs from its dynamic type, the static type will be basics class from the operand’s dynamic type and also the static type shall possess a virtual destructor or even the behavior is undefined.
Basically understood properly, you possess an object of some derived type, and also you hold a pointer into it whose static type is just one of its base classes so, you are ok, so far as you've
Edit well, I had been far too slow :P