[ create a new paste ] login | about

Link: http://codepad.org/nNJaejm3    [ raw code | output | fork ]

lanzkron - C++, pasted on Nov 16:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <new>
using namespace std;

struct foo {
    ~foo() { cout << "destructor\n"; }
    void operator delete(void* p) { 
        cout << "operator delete (not explicitly calling destructor)\n"; 
        free(p);
        cout << "After delete\n"; 
    }
};

int main()
{
    void *pv = malloc(sizeof(foo));
    foo* pf = new (pv) foo; // use placement new
    delete pf;
}


Output:
1
2
3
destructor
operator delete (not explicitly calling destructor)
After delete


Create a new paste based on this one


Comments: