title: Overloading operator ->
body: <p>Here is my code example:</p>
  
  <pre><code>class X
  {
  public:
          void f() {}
  };
  
  class Y : public X
  {
  public:
          X&amp; operator-&gt;() { return *this; }
          void f() {}
  };
  
  int main()
  {
          Y t;
          t.operator-&gt;().f(); // OK
          t-&gt;f(); // error C2819: type 'X' does not have an overloaded member 'operator -&gt;'
                  // error C2232: '-&gt;Y::f' : left operand has 'class' type, use '.'
  }
  </code></pre>
  
  <p>Why the compiler is trying to "move the responsibility" for operator-> from Y to X? When I implement X::op-> then I cannot return X there - compile error says "infinite recursion" while returning some Z from X::op-> again says that Z doesn't have operator->, thus going higher and higher in hierarchy.</p>
  
  <p>Can anyone explain this interesting behavior? :)</p>