奇怪的语法:作用域运算符(::)后面有星号?

发布于 2024-12-19 12:21:28 字数 551 浏览 6 评论 0原文

帮助我理解以下代码片段:

(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() { }    
};

foo.h 中的 typedef 在这里声明的到底是什么?我可以看到它是某种函数指针,但是星号的意义是什么?它似乎正在取消对类型的引用(??),并以某种方式尝试将新的 typedef 指针“附加”到 MyType 的类型(?!?)。

有人可以在这里解释一下吗?真的很困惑:S

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧伤还要旧人安 2024-12-26 12:21:28

void (MyType::*)(SomeOtherType* t) 是一个指向类 MyType 中成员函数的指针,该函数采用一个参数(指向 SomeOtherType 的指针) >) 并且什么也不返回。

FAQ Lite 条目

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.

江挽川 2024-12-26 12:21:28

指向 MyType 成员函数的指针,返回 void 并将指向 SomeOtherType 的指针作为参数。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文