C++ Logo

std-discussion

Advanced search

What's the rational for the precedence of the '.*' and '->*' operators?

From: Shachar Shemesh <shachar_at_[hidden]>
Date: Fri, 14 Jun 2019 14:25:07 +0300

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

Received on 2019-06-14 06:26:58