class Base
{
int n;
public:
Base(int n)
: n(n)
{}
...
}
class Derived : Base
{
public:
Derived(int n)
: Base(n)
{}
}
void function()
{
Derived* obj = new Derived(10);
...
delete obj;
}
I have a similar situation as with the above code, where Derived is just a wrapper of Base. To access the object in function I’m using a Derived pointer on purpose. My understanding is that the whole object it’s allocated on the heap, including the Base part and that delete reclaims all the memory, even if I use a Derived pointer and Base is not polymorphic. Is this correct or there is something more to it ?
Thanks