[ create a new paste ] login | about

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

C++, pasted on Jan 31:
#include <stdio.h>

#include <boost/function.hpp> 
#include <boost/bind.hpp>

class Foo
{
public:
    Foo()                       { printf("Foo::Foo\n"); } 
    ~Foo()                      { printf("Foo::~Foo\n"); }
    Foo(const Foo&)             { printf("Foo::Foo(const Foo&)\n"); }
    Foo& operator=(const Foo&)  { printf("Foo::operator=(const Foo &)\n"); return *this; }
};

void Function(const Foo&)
{
    printf("Function invoked\n");
}

int main(void)
{
    {
        boost::function<void(void)> func;

        {
            Foo f;
            printf("\nConstructing function\n");
            func = boost::bind(&Function, f);
            printf("Construction complete\n\n");
        }

        printf("\nCalling function\n");
        func();
        printf("Calling complete\n\n");
    }
    printf("Function has been destroyed\n");
}


Output:
Foo::Foo

Constructing function
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::~Foo
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::Foo(const Foo&)
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::Foo(const Foo&)
Foo::~Foo
Foo::Foo(const Foo&)
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::~Foo
Foo::~Foo
Construction complete

Foo::~Foo

Calling function
Function invoked
Calling complete

Foo::~Foo
Function has been destroyed


Create a new paste based on this one


Comments: