#include <iostream>
using namespace std;

class unsafe_func
{
public:
	template<class F>
	explicit unsafe_func(F f) : pd(new detail_impl<F>(f)) {
	}

	~unsafe_func() {
		delete pd;
	}

	template<class R, class ... Args>
	R call(Args ... args) const {
		return static_cast< detail_impl<R(*)(Args ...)>* >(pd)->f_(args...);
	}

private:
	unsafe_func(unsafe_func const &);
	unsafe_func& operator=(unsafe_func const &);

	struct detail
	{
		virtual ~detail() {}
	};

	template<class F>
	struct detail_impl : detail
	{
		F f_;
		detail_impl(F f) : f_(f) {
		}
	};

	detail* pd;
};

struct helloworld
{
	void funcA() const {
		std::cout << "void helloworld::funcA()" << std::endl;
	}

	int funcB(int, int) const {
		std::cout << "int helloworld::funcB(int, int)" << std::endl;
		return 0;
	}
};

int main() {
	unsafe_func pf(&helloworld::funcA);
	unsafe_func pf2(&helloworld::funcB);

	helloworld *p = 0;

	pf.call<void>(p);
	pf2.call<int>(p, 0, 0);

	return 0;
}