title: Warning C4150 deletion of pointer to incomplete type when trying to wrap native c++ class
body: <p>I'm trying to write a ref class template in C++/CLI that can be used to wrap a native C++ type based on the advice <a href="https://msdn.microsoft.com/en-us/library/ms235281.aspx" rel="nofollow noreferrer">here</a>. This is what I have so far:</p>
  
  <pre><code>template&lt;class T&gt;
  public ref class NativeWrapper {
    T* ptr_;
  
  protected:
    !NativeWrapper() { delete ptr_; }  // &lt;-- C4150 Warning here!
  
  public:
    NativeWrapper(std::unique_ptr&lt;T&gt; ptr) : ptr_(ptr.release()) {}
  
    T* get() { return ptr_; }
    T* operator-&gt;() { return ptr_; }
  
    ~NativeWrapper() { NativeWrapper::!NativeWrapper(); }
  };
  </code></pre>
  
  <p>I then want to use it as a member in a ref class but I want to use a forward declaration for the native class in the .h file:</p>
  
  <pre><code>// MyManagedClass.h
  
  #include "NativeWrapper.h"
  
  // forward declaration
  class MyNativeClass;
  
  ref class MyManagedClass {
    NativeWrapper&lt;MyNativeClass&gt; my_native_class_;
  public:
    MyManagedClass();
    void doSomething();
  };
  
  // MyManagedClass.cpp    
  
  #include "MyManagedClass.h"
  #include "MyNativeClass.h"
  
  MyManagedClass::MyManagedClass() : my_native_class_(std::make_unique&lt;MyNativeClass&gt;()) { }
  
  void MyManagedClass::doSomething() {
    my_native_class-&gt;doSomething();
  }
  </code></pre>
  
  <p>The destructor of the native class seems to be called correctly but I get the following warning:</p>
  
  <pre><code>Warning C4150 deletion of pointer to incomplete type 'MyNativeClass'; no destructor called
  </code></pre>
  
  <p>See comment indicating the line above.</p>
  
  <p>I've tried explicitly writing a destructor and a finalizer in <code>MyManagedClass.cpp</code> which is what I would do if I encountered a similar problem in native c++ but it doesn't seem to fix the problem.</p>