title: C2440 static_cast cannot convert from base class to derived class
body: <p>I am attempting to understand why casting from a base class to an derived class using pointers compiles fine, but casting using non-pointer object produces the error C2440.</p>
  
  <p>Below I have a base class <code>ThreadedMessage</code> that is inherited by class <code>GPSMessage</code>.</p>
  
  <pre><code>struct ThreadedMessage
  {
    ThreadedMessage()
      : m_Type(0), m_ID(0)
    { }
  
    ThreadedMessage(uint Type, uint ID = 0) :
      m_Type(Type), m_ID(ID)
    { }
  
    uint m_Type;
    uint m_ID;
  };    
  
  struct GPSMessage : public ThreadedMessage
  {
    GPSMessage()
      : ThreadedMessage()
    { }
  
    GPSMessage(double lat, double lon)
      : ThreadedMessage(1), m_lat(lat), m_lon(lon)
    { }
  
    double m_lat;
    double m_lon;
  };
  </code></pre>
  
  <p>In <code>myFunction</code> I am attempting to cast from the base class to the derived class.</p>
  
  <pre><code>void myFunction(const ThreadedMessage&amp; msg)
  {
    const GPSMessage* message = static_cast&lt;const GPSMessage*&gt;(&amp;msg); // Compiles fine
    const GPSMessage message1 = static_cast&lt;const GPSMessage&gt;(msg);   // Error C2440
  }
  </code></pre>
  
  <p>The call to <code>myFunction()</code> looks like this:</p>
  
  <pre><code>GPSMessage msg(21.123, 12.321);
  myFunction(msg);
  </code></pre>
  
  <p>When I compile, the casting of a pointer compiles fine, but the non-pointer casting fails with the following error:</p>
  
  <blockquote>
    <p>error C2440: 'static_cast' : cannot convert from 'const ThreadedMessage' to 'const GPSMessage' No constructor could take the source type, or constructor overload resolution was ambiguous</p>
  </blockquote>
  
  <p>Why am I unable to cast from the base class to the derived class with non-pointer variables?</p>
  
  <p>Compiler is MS VS 2008 C++.</p>
  
  <p>Yes, I have looked at other similar SO questions, but the ones I have read don't seem to answer my question.</p>