user10000100_u user10000100_u - 1 year ago 86
C++ Question

"There is no “reference-to-member” type in C + +", std::bind and boost::bind are in the same boat

Quoting the standard (2003) version (the more recent others are saying the same I think) very end of 8.3.3, bold emphasizing is mine :

A pointer to member shall not point to a static member of a class (9.4), a member with reference type, or
“cv void.” [Note: see also 5.3 and 5.5. The type “pointer to member” is distinct from the type “pointer”,
that is, a pointer to member is declared only by the pointer to member declarator syntax, and never by the
pointer declarator syntax. There is no “reference-to-member” type in C + +. ]

But I see for instance a lot of

boost::bind(&SomeClass::SomeMemberFunction, this, _1)

as well as

std::bind(&SomeClass::SomeMemberFunction, this, std::placeholders::_1)

etc working like a charm, involving
's which seem to be references to member function.

Is the standard simply saying that for instance

int (SomeClass::&RefOnSomeMemberFunction) (int) = SomeClass::SomeMemberFunction

is not a valid assertion in that language, or is there more ?

Answer Source

Your understanding of the wording is correct. The following is ill-formed:

int (SomeClass::&RefOnSomeMemberFunction) (int) = SomeClass::SomeMemberFunction;

In fact, if you look at the grammar rules, there's only

nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt D1

Your understanding of what happens in the calls to boost::bind and std::bind you mentioned is flawed. In this context, unary & is the addressof operator, and it yields pointer to member (function). That pointer is defined in the paragraph you quoted.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download