[ create a new paste ] login | about

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

C++, pasted on May 21:
#include <iostream>

class Base {
public:
	virtual ~Base() {}
	virtual void call(int i) = 0;
};

template<class F>
class Foo : public Base {
	F f;
public:
	Foo(F f) : f(f) {}
	virtual void call(int i) { f(i); }
};

class Holder {
	Base* b;
public:
	template<class F>
	Holder(F f) : b(new Foo<F>(f)) {}
	~Holder() { b->call(0); delete b; }
};

void foo(int i, int j = 0) { std::cout << i << std::endl; }

int main() {
	Holder h(foo);
}


Output:
1
0


Create a new paste based on this one


Comments: