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:
struct X {
int foo;
};
struct Y {
X x;
X* operator->() { return &x; }
};
struct Z {
Y y;
Y& operator->() { return y; }
};
Z z;
z->foo = 42; // Works! Calls both!
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->b
syntax, by using this strange special case; I could not find a way to get (*a).b
to work similarly.
Not sure that this answers your question; really I'm saying, "Good question, but it's even weirder than that!"