title: [C++]Covariant return types
body: <p>I have a <code>VectorN</code> class, and a <code>Vector3</code> class inherited from <code>VectorN</code> (which can handle cross products for example). I have trouble determining the return types of the different operators. Example:</p>
  
  <pre><code>class VectorN
  {
  public:
     VectorN(){};
     virtual VectorN operator*(const double&amp; d) {.....};
     std::vector&lt;double&gt; coords;
  };
  
  class Vector3 : public VectorN
  {
  public:
    Vector3(){};
    virtual Vector3 operator*(const double&amp; d) {....};
  };
  </code></pre>
  
  <p>This particular example produces a C2555 error:</p>
  
  <blockquote>
    <p>'Vector3::operator *': overriding virtual function return type differs and is not covariant from 'VectorN::operator *', see declaration of 'VectorN::operator *'.</p>
  </blockquote>
  
  <p>The problem is that I don't return a reference to a <code>Vector3</code>, and that the <code>Vector3</code> class is not fully defined at the declaration of the <code>operator*</code>. However, I want my <code>operator*</code> to be virtual, and I want to return a <code>Vector3</code> when I multiply a <code>Vector3</code> with a constant (otherwise, if I do <code>(Vector3*double).crossProduct(Vector3)</code>, it would return an error).</p>
  
  <p>What can I do ?</p>
  
  <p>Thanks!</p>