Itβs hard for me to understand the explanation from strustrup about the difficulties that need to be encountered if the operator overloads for '.' was allowed.
See this quote from Bjarne Stroustrup:
Operator. (dot) can in principle be overloaded using the same technique as for β. However, this may lead to questions about whether the operation is intended to overload the facility. or the object referenced. For instance:
class Y { public: void f();
In the example above, why when running xf() ?
there is any confusion
Y& operator.() { return *p; }
That's what I think:
- operator. () is called on x, so it is not obivous and intuitive, what
Y& operator.()( return *p; } should be called? - After returning
*p , which points to an object of type Y and, therefore, Y::f() should be called finally (not X::f() )
What am I missing in explaining strustup? Why is it not easy?
source share