Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar03 / src / dynamic-array / examples / placement-new-memory-strategy.cpp
blob: 693b95cac22dcd0f41f8f96318e1f9a0b8937a08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

struct E
{
    E()
    {
        std::cout << "constr" << std::endl;
    }

    ~E()
    {
        std::cout << "destr" << std::endl;
    }
};

int main()
{
    std::cout << "operator new called" << std::endl;
    E* e = static_cast<E*>(operator new(sizeof(E)));
    std::cout << "placement new called" << std::endl;
    new (e) E();

    std::cout << "destructor manually called" << std::endl;
    e->~E();
    std::cout << "operator delete called" << std::endl;
    operator delete(e, sizeof(E));
}