Reputation: 258
I am trying to set a parameter in PassiveQueueBase which is child class and call it in another child class PriorityScheduler for Base Class IPassiveQueue.
PriorityScheduler is inherited from SchedulerBase which has a pointer (inputQueue) pointing at who ever is of type IpassiveQueue and going to invoke PacketEnqueued() function to PriorityScheduler. This is shown in this code
class INET_API SchedulerBase : public cSimpleModule, public IPassiveQueue, public IPassiveQueueListener
{
public:
virtual void packetEnqueued(IPassiveQueue *inputQueue) override;
};
Note: IpassiveQueue.h has no .cc file it is an interface file for many other classes.
What I tried to do is shown below,
class INET_API IPassiveQueue
{
public:
simtime_t sendWindowStart;
simtime_t sendWindowEnd;
virtual void setWindows() {};
};
class INET_API PassiveQueueBase : public cSimpleModule, public IPassiveQueue
{ protected:
void setWindows(simtime_t SWS,simtime_t SWE);
};
void PassiveQueueBase :: setWindows(simtime_t SWS,simtime_t SWE)
{ SWS = 3; SWE = 4;
sendWindowStart = SWS;
sendWindowEnd = SWE;
};
bool PriorityScheduler::schedulePacket()
{
IPassiveQueue *pqueue;
pqueue->setWindows();
sendWindowStart = inputQueue->sendWindowStart;
sendWindowEnd = inputQueue->sendWindowEnd;
}
I had an error by running the simulation as shown below
Simulation terminated with exit code: 139 Working directory: /home/usrname/omnetpp-5.0/samples/inet/examples/mysimulation Command line: opp_run -r 0 -n ..:../../src:../../tutorials -l ../../src/INET --debug-on-errors=false omnetpp.ini
Also I have exclamation mark on this line
pqueue->setWindows();
with this note
‘Pqueue’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Upvotes: 0
Views: 255
Reputation: 258
Well I thought about using inputQueue itsself as pointer instead of creating new pointer on the function that exactly the same as in the child class but empty and it worked.
class INET_API PriorityScheduler : public SchedulerBase
{
protected:
virtual bool schedulePacket() override;
simtime_t sendWindowStart;
simtime_t sendWindowEnd;
simtime_t SWS;
simtime_t SWE;
};
bool PriorityScheduler::schedulePacket()
{
inputQueue->setWindows( SWS, SWE);
sendWindowStart = inputQueue->sendWindowStart;
sendWindowEnd = inputQueue->sendWindowEnd;
}
class INET_API IPassiveQueue
{
public:
simtime_t sendWindowStart;
simtime_t sendWindowEnd;
virtual void setWindows(simtime_t SWS,simtime_t SWE) {};
}
class INET_API PassiveQueueBase : public cSimpleModule, public IPassiveQueue
{
protected:
virtual void setWindows(simtime_t SWS,simtime_t SWE) {};
}
void PassiveQueueBase::setWindows(simtime_t SWS,simtime_t SWE)
{ SWS = 1; SWE=5;
sendWindowStart = SWS;
sendWindowEnd = SWE;
}
Upvotes: 0
Reputation: 1189
you have not allocated pqueue
yet and you are using it.
IPassiveQueue *pqueue;
this one still points on unknown location on memory.
to fix this you can allocate it using new
IPassiveQueue *pqueue = new IPassiveQueue;
and make sure to delete it using delete
delete pqueue;
you could also allocate it using smart pointer which will be more safe
std::unique_ptr<IPassiveQueue> pqueue(new IPassiveQueue);
Upvotes: 1