I am doing a network simulation using Omnet++ which is based on C++. I am trying to define a class for a certain module using the following code:
#ifndef __PROJECT_IMS_SLF_H_
#define __PROJECT_IMS_SLF_H_
#include <omnetpp.h>
#include "mDIAMETER_m.h"
#include "IPPacket_m.h"
class SLF : public cSimpleModule
{
public:
mDIAMETER *generateDIAMETERmsg(const char* name, long userID, bool registered, std::string server);
IPPacket *generateIPPacket(int srcIP,int desIP);
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
private:
int MyIP;
int N = par("N");
struct Registry {
long UserID;
bool Registered;
std::string Server;
};
struct Registry MyReg[N]; // Create a Registry Table for all UEs
};
#endif
I am getting the following error: "invalid use of non-static data member SLF::N". I know I'm declaring N inside the class definition as a private variable but I have to do so because N is a parameter related to the module which is defined as an instance of the class SLF and it is read from the configurations of this module using the OMNET++ defined function "par".
If I declareMyReg[N]inside the initialize function it works but the problem is that I need to use this variable inside the other function (handleMessage). Any hints?
Thanks in advance!
std::vector, then you don't need theNmember variable as you can initialize the vector to the correct size in the constructor.par("N")looks like a function call (although not shown in your question) that returns the value at runtime. The compiler needs to value at compile time when you declareMyReg[N]'. That's the reason you need to allocate the Registry objects meomry at runtime.