Hello.
I was just doing a sketch of polymorphism for my project and i came to a following situation that made me think.
If i have base and derived classes, i declare a pointer to base class and set it to (new derived class) and then call delete base class object i made.
The deconstructor for base class is called? and the object is holding derived class!
Thus making memory leak? or em i missing something;
class Base
{
public:
Base(){}
int q;
};
class Derived : public Base
{
public:
Derived(){}
int q,w;
};
int main()
{
Base * one;
one = new Derived;
delete one;
return 0;
}
Here a leak of one int size will occur?
If so, how would the base class know to call its pointing to deconstructor?