Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ lol

Name: Anonymous 2011-03-29 20:53

so how does one store a pointer to a member function and the object from which to call that function, and then call said function from said object?

example:

struct test {
 /*generic function object*/ fun_ptr;
 some_object* object_instance;
} this_test;

some_object new_obj;
this_test.fun_ptr = &some_object::some_function;
this_test.object_instance = &new_obj;

this_test.object_instance->this_test.fun_ptr(/*arguments*/);

???

Name: Anonymous 2011-03-29 23:10


class some_object
{
public:
    int some_function(int a, int b)
    {
        return a + b;
    }
};

template<typename ClassT, typename FuncT> struct test
{
    FuncT(ClassT::* fun_ptr);
    ClassT* object_instance;
};

    some_object new_obj;
    test<some_object, int(int, int)> this_test;

    this_test.object_instance = &new_obj;
    this_test.fun_ptr = &some_object::some_function;

    int ret = (*(this_test.object_instance).*this_test.fun_ptr)(1, 2);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List