KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: Error with address of parenthesized member function In this recent question the OP ran into a strange provision of the C++ language that makes it illegal to take the address of a member function if that member function name is parenthesized. For example, this code is illegal: struct X { void foo(); }; int main() { void (X::* ptr)(); ptr = &(X::foo); // Illegal; must be &X::foo } I looked this up and found that it's due to ยง5.3.1/3 of the C++ ISO spec, which reads A pointer to member is only formed when an explicit & is used and its operand is a qualified-id not enclosed in parentheses [...] Does anyone have any idea why the spec has this rule? It's specific to pointers-to-member, so I would suspect that there is some grammatical ambiguity that this resolves, but I honestly haven't the faintest idea what it might be.
Tags (comma-separated)
Save Edits
Cancel