C++ Logo

STD-DISCUSSION

Advanced search

Subject: What's the rational for the precedence of the '.*' and '->*' operators?
From: Shachar Shemesh (shachar_at_[hidden])
Date: 2019-06-14 06:25:07


Hello,


The member/method pointer dereference operators ('.*' and '->*') are listed as having level 4 priority. This means that in the expression:

   a.*b()


(which you'll necessarily write in order to dereference b as a pointer to method) the function call operator is evaluated first, so the expression is the same as:

   a.*(b())


This seems strange, as it guarantees that almost any use of pointers to methods would require extra parenthesis like so:

   (a.*b)()


To me, it seems that those operators should have been at priority level 2 than these parenthesis would have become unnecessary with no adverse effect (at least as far as I could find).


Is there some reason I've missed for defining them at priority level 4?


Thank you,

Shachar


STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups