title: Inability to overload Dot '.' operator in c++
body: <p>I have hard time understanding the explanation from Stroustrup for what difficulties one must have faced, if operator overloading for '.' was allowed.</p>
  
  <p>See this quote from Bjarne Stroustrup:</p>
  
  <blockquote>
    <p>Operator . (dot) could in principle be overloaded using the same technique as used for ->. However, doing so can lead to questions about whether an operation is meant for the object overloading . or an object referred to by . For example:</p>
  </blockquote>
  
  <pre><code>class Y {
  public:
      void f();
      // ...
  };
  
  class X {    // assume that you can overload .
      Y* p;
      Y&amp; operator.() { return *p; }
      void f();
      // ...
  };
  
  void g(X&amp; x)
  {
      x.f();    // X::f or Y::f or error?
  }
  </code></pre>
  
  <p>In the above example why should there be any confusion while executing <code>x.f()</code>  ?</p>
  
  <pre><code>Y&amp; operator.() { return *p; }
  </code></pre>
  
  <p>Here is what i think:</p>
  
  <ol>
  <li>operator.() is called on x hence isn't it obvious and intuitive that <code>Y&amp; operator.()( return *p; }</code> should be called ?</li>
  <li>Upon returning <code>*p</code> which points to object of type Y and hence <code>Y::f()</code> should be called finally ( not <code>X::f()</code> )</li>
  </ol>
  
  <p>What am i missing in Stroustup's explanation? Why is it not straightforward?</p>