title: Pointer to an abstract class
body: <p>I am trying to wrap unmanaged c++ code using c++/cli. In C++/cli a class has to be declared <em>abstract</em> if it has all <em>pure virtual</em> functions. Now suppose I have the following code in C++:</p>
  
  <pre><code>class A{
  public:
    virtual ~A();
    virtual void foo() = 0;
    virtual void boo() = 0;
    virtual void goo() = 0;
  };
  inline
  A::~A()
  {
  }
  
  class B
  {
  public:
    B();
    A* getA() const;
  };
  
  inline A* B::getA() const
  {
    //do something
    return (A *) //of something;
  }
  </code></pre>
  
  <p>As per above I can return <em>A*</em> without any errors. Now suppose I wrap the above code as follows:</p>
  
  <pre><code>public ref class manA abstract 
  {
  public:
    manA(A*);
    virtual ~manA();
    virtual void Foo() = 0;
    virtual void Boo() = 0;
    virtual void Goo() = 0;
  private:
    A* m_A;
  };
  
  inline
  manA::~manA()
  {
  }
  
  inline
  manA::manA(A*)
  {
    //data marshalling to convert A* to manA
  }
  
  public ref class manB
  {
  public:
    manB();
    manA ^ GetA();
  private:
    B * m_B;
  };
  
  inline manB::manB()
  {
    m_B = new B;
  }
  
  inline manA ^ manB::GetA()
  {
    A *value = m_B-&gt;getA();
    return gcnew manA(value);
  }
  </code></pre>
  
  <p>now if I do the above I get a <em>a class declared as 'abstract' cannot be instantiated</em> error.</p>
  
  <p>Is there any solution for this?</p>
  
  <p><strong>Note:</strong> the class A defines the interface for all possible implementations of it. So maybe there is a way to define manA such that it is not abstract and hence can be instantiated?</p>
  
  <p>I found a solution to the problem:</p>
  
  <p>Remove the constructor from <em>manA</em> and use a <em>property</em></p>
  
  <pre><code>public:
  property A* UnmanagedObject 
  {
    void set(A* unmanagedObjPtr)
    {
      //Or other data marshalling
      m_A = (A *)(unmanagedObjPtr);
    }
  }
  </code></pre>
  
  <p>and inside manB do:</p>
  
  <pre><code>inline manA ^ manB::GetA()
  {
    A *value = m_B-&gt;getA();
    manA ^ final;
    final-&gt;UnmanagedObject  = value;
    return final;
  }
  </code></pre>