The standard definition of the built-in operator & in C ++ means that only if the & parameter is an identifier with qualifications, which means something like Class::Member , then & leads to an element, Brackets are that it is no longer an identifier with qualifications, so it tries to parse X::f directly, which is illegal in this context: you assign int (*)(long) to int (X::*)(int) .
The distinction between the two cases eliminates the ambiguity. Let's say that you have:
struct X { int m; }; struct Y { int m; }; struct Z : X, Y { void F(); }; void Z::F() { int X::*p1 = &X::m; int *p2 = &(X::m); }
Here &X::m is a member pointer, while &(X::m) is a regular int pointer, using the X:: qualification to resolve the ambiguity between X m and Y m .
Myria source share