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