#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

struct Test
{
    Test() { cout << "Выделяем кучу памяти\n"; }
    ~Test() { cout << "Освобождаем кучу памяти\n"; }
    virtual void foo()
    {
        new ( this ) Test;
    }

    virtual void bar()
    {
        new ( this ) Test;
        foo();
    }
};

int main()
{
    Test test;
    test.bar();
    return 0;
}

