title: c++ forward declaration of pure virtual class
body: <p>I have a forward deceleration problem. I had a normal class before, called <code>GlobalCWND</code>, it was instantiated and used in another class <code>ProtocolContext</code>.</p>
  
  <p>I forward declare the ProtocolContext class in <code>Requestor.h</code>.</p>
  
  <p>You can see the related part of the code of this 2 classes.</p>
  
  <p>============Protocol Context========</p>
  
  <pre><code> class Requestor&lt;RequestorStrategy&gt;;
   class Receiver&lt;ReceiverStrategy&gt;;
  
   class ProtocolContext : public Object
   {
   public:
     ProtocolContext(Ptr&lt;SubscriptionContext&gt; , Ptr&lt;ReceiverStrategy&gt; , Ptr&lt;
         RequestorStrategy&gt; );
  .......
  
   ProtocolContext::ProtocolContext(Ptr&lt;SubscriptionContext&gt; sctx, Ptr&lt;
        ReceiverStrategy&gt; rec, Ptr&lt;RequestorStrategy&gt; req) :
      receiver(rec), requestor(req)
    {
      m_sctx = sctx;
      Ptr&lt;GlobalCWND&gt; m_globalCWND = Create&lt;GlobalCWND&gt; (this);
      cout &lt;&lt; "Initializing Protocol Context for rid"
          &lt;&lt; m_sctx-&gt;GetMetaDataStrategy()-&gt;GetRid() &lt;&lt; endl;
      m_ph = Create&lt;PacketHandler&gt; (sctx);
    }
  </code></pre>
  
  <p>=================Requestor.h=========</p>
  
  <pre><code> class ProtocolContext;
  
   class RequestorStrategy : public Object
   {
  
   public:
     RequestorStrategy()
     {
     }
     ;
     ~RequestorStrategy()
     {
     }
     ;
     /* Transitions */
     virtual void
     Trans(Ptr&lt;ProtocolContext&gt; , Ptr&lt;Packet&gt; ) = 0;
   };
  
  .....
  </code></pre>
  
  <p>It worked properly before. Now I have change the <code>GlobalCWND</code> to a virtual class and In the protocol Context constructor I have this code:</p>
  
  <pre><code>ProtocolContext::ProtocolContext(Ptr&lt;SubscriptionContext&gt; sctx, Ptr&lt;
        ReceiverStrategy&gt; rec, Ptr&lt;RequestorStrategy&gt; req) :
      receiver(rec), requestor(req)
    {
      m_sctx = sctx;
      Ptr&lt;GlobalCWND&gt; m_globalCWND = Create&lt;GlobalCWNDSimple&gt; (this);
  
  ..............
  }
  </code></pre>
  
  <p>But now I get this error:</p>
  
  <pre><code> GlobalCWND.h:21:   instantiated from here
  ptr.h:441: error: invalid use of incomplete type ‘struct
  ProtocolContext’
  Requestor.h:16: error: forward declaration
  of ‘struct ProtocolContext’
  </code></pre>
  
  <p>the error lines are:</p>
  
  <pre><code>line 21 of GlobalCWND() is    GlobalCWND (){};
  and line 16 of Requestor.h is class ProtocolContext;
  </code></pre>
  
  <p>Ptr class is actually creating pointer to the object, line 441 of ptr.h is the last line of this function:</p>
  
  <pre><code>template &lt;typename T&gt;
  Ptr&lt;T&gt;::~Ptr ()
  {
   if (m_ptr != 0)
     {
       m_ptr-&gt;Unref();
     }
  }
  </code></pre>
  
  <p>The code for <code>GlobalCWND</code> starts like this:</p>
  
  <pre><code> class ProtocolContext;
  
    class GlobalCWND : public Object
    {
    public:
      GlobalCWND (){};
      GlobalCWND (Ptr&lt;ProtocolContext&gt;){};
      ~GlobalCWND (){};
  
      static TypeId GetTypeId(){
        static TypeId tid = TypeId("GlobalCWND")
        .SetParent&lt;Object&gt; ()
        ;
        return tid;
      };
  </code></pre>