如果函数指针不需要和号,为什么boost :: bind需要一个? [英] If ampersands aren't needed for function pointers, why does boost::bind require one?

查看:145
本文介绍了如果函数指针不需要和号,为什么boost :: bind需要一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为函数指针不需要和号:

I've always believed that function pointers don't require an ampersand:

函数指针需要一个&符号

然而,我看到的每个例子使用 boost :: bind 显示一个,而且在大多数情况下,我的编译器如果省略它,会给出一个通常不可更改的错误消息。

Yet, every example I've seen of using boost::bind shows one, and my compiler - in most situations - gives a typically inscrutable error message if it's omitted.

synchronize(boost::bind(&Device::asyncUpdate , this, "ErrorMessage"));  // Works

synchronize(boost::bind(Device::asyncUpdate , this, "ErrorMessage"));   // Fails



假设 boost :: bind 的第一个参数基本上是函数指针?

Am I wrong in assuming that boost::bind's first parameter is basically function pointer?

推荐答案

函数指针不需要它,成员函数指针。

Function pointers don't need it, member function pointers do.

Device :: asyncUpdate 是成员函数,因为你可以猜到,因为它被绑定到

Device::asyncUpdate is member function, as you could guess because it is being bound to this.

这是从n3337,5.3.1 / 4的规范性引文

Here's a normative quote from n3337, 5.3.1/4


指向成员的指针只有在显式&并且其操作数是未括在括号中的合法ID。

A pointer to member is only formed when an explicit & is used and its operand is a qualified-id not enclosed in parentheses.

这篇关于如果函数指针不需要和号,为什么boost :: bind需要一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆