문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top