The pointer to member dereference operator (.* and ->*) in C++ is of operator precedence 4, while the function call operator is of precedence 2. This pretty much guarantees that parenthesis will be required:
#include <iostream>
struct A {
int b;
int func1( int a ) { return a+b+1; }
int func2( int a ) { return 2*a+b; }
};
int main() {
A a;
a.b = 3;
int (A::*ptr)(int);
ptr = &A::func1;
std::cout<<
(a.*ptr) // <- these parenthesis
( 2 ) << "\n";
}
It seems to me that defining .* as priority 2 would (with left to right associativity) negate the need of the parenthesis with no obvious ill side effects.
What was the reason for choosing this priority?