Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If ampersands aren't needed for function pointers, why does boost::bind require one?

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

Do function pointers need an ampersand

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

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

like image 260
Roddy Avatar asked Aug 19 '13 11:08

Roddy


1 Answers

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

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

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

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

like image 51
jrok Avatar answered Oct 13 '22 05:10

jrok