Wouldn’t it make sense if p->m was just syntactic sugar for (*p).m? Essentially, every operator-> that I have ever written could have been implemented as follows:
Foo::Foo* operator->()
{
return &**this;
}
Is there any case where I would want p->m to mean something else than (*p).m?
operator->()has the bizarre distinction of implicitly being invoked repeatedly while the return type allows it. The clearest way to show this is with code:I recall an occasion when this behaviour was necessary to enable an object to behave as a proxy for another object in a smart-pointer-like context, though I can’t remember the details. What I do remember is that I could only get the behaviour to work as I intended using the
a->bsyntax, by using this strange special case; I could not find a way to get(*a).bto work similarly.Not sure that this answers your question; really I’m saying, “Good question, but it’s even weirder than that!”