Why work the function call operator not together with a member-of-pointer operator?
struct F
{
void operator()(){}
};
int main()
{
F * f = new F;
f->(); // Why this doesn't compile?
}
I guess the C++ gods simply thought the syntax was too obscure. The correct syntax is either:
f->operator()();
Or:
(*f)()
If the ->
operator isn't overloaded then f->
is roughly equivalent to (*f).
, (*f).()
doesn't compile either, you would have to use:
(*f).operator()();
您应该将其称为f->operator()()
或(*f)()
。
I don't think there's any specific reason.
Both ->
and .
expect the name of a member to follow, and you haven't provided one.
There's just no need to create a special case in the grammar to permit that. It's complicated enough as it is!
(*f)()
is the way to go.
Sorry if that's brief and unfulfilling, but if you're looking for some deep meaning here I think you're bound to be disappointed!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.