title: When does operator<< refer to the insertion operator and when to the bitwise left shift?
body: <p>When does <code>operator &lt;&lt;</code> refer to the insertion operator and when does it refer to the bitwise left shift?</p>
  
  <p>This will output <code>10</code>, and <code>operator &lt;&lt;</code> refers to the left shift. </p>
  
  <pre><code>cout &lt;&lt; a.b() &lt;&lt; a.a.b &lt;&lt; endl;  
  </code></pre>
  
  <p>And this will output <code>11</code>, <code>operator &lt;&lt;</code> refers to the insertion operator.</p>
  
  <pre><code>cout &lt;&lt; a.b();
  cout &lt;&lt; a.a.b ;
  </code></pre>
  
  <p>I am confused, when will <code>operator &lt;&lt;</code> (when use with <code>cout</code>)  refer to the left shift operator?</p>
  
  <pre><code>#include &lt;iostream&gt; 
  using namespace std; 
  
  class A { 
  public:
      A() { a.a = a.b = 1; }
  
      struct { int a, b; } a;
  
      int b(); 
  }; 
  
  int A::b(){
      int x=a.a;
      a.a=a.b;
      a.b=x; 
      return x;
  };
  
   int main(){
      A a; 
      a.a.a = 0; 
      a.b(); 
  
      cout &lt;&lt; a.b() &lt;&lt; a.a.b &lt;&lt; endl;      // ?????
      return 0;
  }
  </code></pre>