[ create a new paste ] login | about

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

C++, pasted on Apr 22:
#include <iostream>

class Foo
{
    int x;
public:
     Foo() { std::cout << "Foo!\n"; }
     virtual ~Foo() { std::cout << "~Foo!\n"; }

    void *operator new(size_t size)
    {
        std::cout << "new Foo( " << size << " )!\n";
        return ::operator new(size);
    }

    void operator delete(void *ptr)
    {
        std::cout << "delete Foo!\n";
        ::operator delete(ptr);
    }
};

class Bar : public Foo
{
     int y;
public:
     Bar() { std::cout << "Bar!\n"; }
     ~Bar() { std::cout << "~Bar!\n"; }
};

int main()
{
    Foo *foo = new Foo();
    delete foo;

    Bar *bar = new Bar();
    delete bar;
}


Output:
1
2
3
4
5
6
7
8
9
10
new Foo( 8 )!
Foo!
~Foo!
delete Foo!
new Foo( 12 )!
Foo!
Bar!
~Bar!
~Foo!
delete Foo!


Create a new paste based on this one


Comments: