Question

Help me understand the following code snippet:

(foo.h)

class Foo
{
   public:
        typedef void (MyType::*Handler)(SomeOtherType* t);

        Foo(Handler handler) : handler_(handler) { }

   private:
        Handler handler_;
};

(mytype.h)

class MyType
{
     public:
          MyType() { }
          void fun1() { }
          void fun2() { }    
};

What exactly is the typedef in foo.h declaring here? I can see that it's a function pointer of some kind but what's the significance of the asterisk? It appears to be de-referencing a type (??) and somehow trying to "attach" the newly typedef'd pointer to the type of MyType (?!?).

Can someone shed some light here please? Really confused :S

Was it helpful?

Solution

void (MyType::*)(SomeOtherType* t) is a pointer to a member function in class MyType that takes one argument (pointer to SomeOtherType) and returns nothing.

FAQ Lite entry.

OTHER TIPS

Pointer to a MyType member function returning void and taking pointer to SomeOtherType as a parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top