title: CastToBase unresolved external symbol error when using abstract class derived from WinRT Grid Class?
body: <p>This is something very odd I found working with C++/CX.</p>
  
  <p>Given following:</p>
  
  <pre><code>ref class Duper : public Windows::UI::Xaml::Controls::Grid{
  internal:
      Duper(){}
      virtual void doNothing() = 0;
  public:
      virtual ~Duper(){}
  
  };
  
  ref class Sub : public Duper
  {
  internal:
      Sub(){}
      void doNothing()override{}
  public:
      virtual ~Sub(){}
  };
  </code></pre>
  
  <p>Calling Sub class:</p>
  
  <pre><code>Sub^ test = ref new Sub();
  test-&gt;doNothing();
  </code></pre>
  
  <p>Works fine as expected, but when running this:</p>
  
  <pre><code>Sub^ test = ref new Sub();
  test-&gt;Width = 20;
  </code></pre>
  
  <p>You get greeted error similar to this</p>
  
  <pre><code>Error   226 error LNK2001: unresolved external symbol "public: class Windows::UI::Xaml::Controls::Grid ^ __stdcall XSideView::__abi_CastToBase(void)" (?__abi_CastToBase@XSideView@@Q$AAGP$AAVGrid@Controls@Xaml@UI@Windows@@XZ)    D:\OZSOURCE70\OZReportViewer\OZWRTViewer\ozrv\platform.lib(OZCViewerSideView.obj)   ozrv_dll
  </code></pre>
  
  <p>You can however get around calling CastToBase by doing this:</p>
  
  <pre><code>Grid^ base = dynamic_cast&lt;Grid^&gt;(test3);
  base-&gt;Width = 30;
  </code></pre>
  
  <p>And it will work fine.</p>
  
  <p>Can someone please explain to me why this happens? Is there a way to fix this other than explicitly casting to Grid class every time I use this class? Although I haven't bothered to test with other ref classes, I bet they will have similar problem.</p>
  
  <p>PS: It is possible this is a bug and have been fixed in later versions(I'm currently developing in Windows 8.1 with VS2013)</p>
  
  <p>PPS: CastToBase documentation :  <a href="https://docs.microsoft.com/en-us/cpp/windows/interfacetraits-casttobase-method" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/cpp/windows/interfacetraits-casttobase-method</a></p>