[ create a new paste ] login | about

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

C++, pasted on Mar 8:
    template<typename O, void (O::* f)()>
    struct NonConstFunc
    {
        static void call(O* o)
        {
            (o->*f)();
        }
    };

    template<typename O, void (O::* f)() const>
    struct ConstFunc
    {
        static void call(O* o)
        {
            (o->*f)();
        }
    };

    template<typename Obj, typename Function>
    void call(Obj* o)
    {
        Function::call(o);
    }


struct foo
{
	void bar()
	{
		cout << "hey" << endl;
	}
	void constbar() const
	{
		cout << "ho" << endl;
	}
};

int main()
{
    foo f;
    call<foo,NonConstFunc<foo,&foo::bar> >(&f);
    call<foo,ConstFunc<foo,&foo::constbar> >(&f);
}


Output:
1
2
hey
ho


Create a new paste based on this one


Comments: