title: C++ : Ternary Operator (Conditional Operator) and its Implicit Type Conversion Rules
body: <p>Are there rules for implicit type conversion for arguments of the ternary operator?</p>
  
  <p>The ternary operator always needs to return the same type. This type is determined solely by the second and third argument (<code>1st ? 2nd : 3rd</code>), therefore both arguments are converted to this type. How is this type determined?</p>
  
  <p>To be more specific, I tested an example:</p>
  
  <pre><code>class pointclass
  {
      pointclass();
  
      pointclass( int i );    // (pointclass)(int)
      operator bool() const;  // (bool)(pointclass)
  };
  </code></pre>
  
  <p>I have a class (<code>pointclass</code>), which enables implicit conversion from <code>int</code> to <code>pointclass</code> and implicit conversion from <code>pointclass</code> to <code>bool</code>. </p>
  
  <pre><code>int i;
  pointclass p;
  bool b;
  
  b ? p : i;  // (bool) ? (int)(bool)(pointclass) : (int)
  b ? i : p;  // (bool) ? (int) : (int)(bool)(pointclass)
  </code></pre>
  
  <p>Using the ternary operator, I compare <code>pointclass</code> and <code>int</code>. The compiler uses implicit conversion from <code>pointclass</code> to <code>bool</code> and then the standard conversion from <code>bool</code> to <code>int</code>. This is done, no matter if I exchange 2nd and 3rd arguments. <strong>Why does it not convert <code>int</code> to <code>pointclass</code>?</strong></p>
  
  <p>Using a comparison operator is much more straightforward:</p>
  
  <pre><code>p == i;     // (pointclass) == (pointclass)(int)
  i == p;     // (int) == (int)(bool)(pointclass)
  </code></pre>
  
  <p>The type of the arguments is simply determined by the first argument.</p>
  
  <p>But I don't understand the type conversion rules of the ternary operator. For me it seems just like using the way of most conversions.</p>