title: Linux g++ compile error: error: expected ',' or '...' before '||' token
body: <p>Let me start by saying that this compiles and runs fine in Visual Studio.  But when I compile the same file on Linux (g++), I get compile errors for declaration and implementation of overload of the <code>&lt;&lt;</code> operator.</p>
  
  <p>The relevant part of the code is extracted below. (It is a .cpp file with Google Test cases in it, and has class and method definitions sprinkled through to support the test cases.)  I elided all but the relevant parts of the code (I hope).</p>
  
  <pre><code>class orderrequest : public msg_adapter {
  public:
      // ... snip
  
      friend bool operator ==(const orderrequest &amp;or1, const orderrequest &amp;or2);
      friend ostream&amp; operator &lt;&lt;(ostream &amp;out, const orderrequest &amp;or);  // compiler error here
  };
  
  bool operator ==(const orderrequest &amp;or1, const orderrequest &amp;or2) {
      bool result = or1.symbol == or2.symbol
          &amp;&amp; or1.orderQty == or2.orderQty;
  
      // ...  snip
      return result;
  
  }
  
  // compiler error here
  ostream&amp; operator &lt;&lt;(ostream &amp;out, const orderrequest &amp;or) {
  
      out &lt;&lt; "symbol=" &lt;&lt; or.symbol &lt;&lt; ",orderQty=" &lt;&lt; or.orderQty;
      return out;
  }
  </code></pre>
  
  <p>The compile throws a few errors, all seemingly related to trying to overload the <code>&lt;&lt;</code> operator:</p>
  
  <pre><code>EZXMsgTest.cpp:400: error: expected ',' or '...' before '||' token
  EZXMsgTest.cpp:428: error: expected ',' or '...' before '||' token
  EZXMsgTest.cpp: In function 'std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const orderrequest&amp;)':
  EZXMsgTest.cpp:430: error: expected primary-expression before '||' token
  EZXMsgTest.cpp:430: error: expected primary-expression before '.' token
  EZXMsgTest.cpp:430: error: expected primary-expression before '||' token
  EZXMsgTest.cpp:430: error: expected primary-expression before '.' token
  </code></pre>
  
  <p>Line 400 is the <code>friend ostream&amp; operator &lt;&lt;</code> line, and line 430 is the method implementation for the <code>&lt;&lt;</code> operator.  </p>
  
  <p>Also, I'm not sure why the compiler error references the "||" token.  (I am puttied to server, and I followed some instructions to set locale to "C" which improved output somewhat, but it still doesn't look right.)</p>
  
  <p>Thanks everyone.</p>