C
cronusf
If you have:
#include <iostream>
using namespace std;
class Base
{
public:
~Base()
{
cout << "~Base()" << endl;
}
int x;
};
class Derived : public Base
{
public:
~Derived()
{
cout << "~Derived()" << endl;
}
int y;
int z;
};
int main()
{
Base* b = new Derived;
delete b;
}
Only ~Base() is called, which is expected since it is not virtual.
However, when delete is called, will it free the memory allocated for
the variables y and z?
#include <iostream>
using namespace std;
class Base
{
public:
~Base()
{
cout << "~Base()" << endl;
}
int x;
};
class Derived : public Base
{
public:
~Derived()
{
cout << "~Derived()" << endl;
}
int y;
int z;
};
int main()
{
Base* b = new Derived;
delete b;
}
Only ~Base() is called, which is expected since it is not virtual.
However, when delete is called, will it free the memory allocated for
the variables y and z?