#include <iostream>
#include <iomanip>

using namespace std;

class Base
{
public:
    Base()  { ptr = new int[100]; cout << "alloc mem at " << ptr << endl; }
    ~Base() { delete [] ptr; cout << "free mem at " << ptr << endl; }
    int * ptr;
};

class Derived1
{
public:
    Derived1(int x, int y):x(x),y(y){}
    Derived1(int x)
    {
        new(this) Derived1(x,0);
    }
    int x, y;
    Base b;
};

class Derived2: public Base
{
public:
    Derived2(int x, int y):x(x),y(y){}
    Derived2(int x)
    {
        new(this) Derived2(x,0);
    }
    int x, y;
};


int main(int argc, const char * argv[])
{
    Derived1 d1(5);
    Derived2 d2(5);
}
