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]
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);