Question

Sorry if this question maybe asked before but I couldn't find a proper answer for it. I am trying to use my own class file inside another class which was already written by different people. The whole program is based on Omnet++. Before building everything seems to be alright but as soon as I build the program gives me an error of

undefined reference to `RatePrediction::RatePrediction(double, double, double)

I am trying to use RatePrediction in CentralEntity and this is what I've done:

In RatePrediction.cc :

#include "CentralEntity.h"
RatePrediction::RatePrediction(double gs,double gi, double dataRate):
            gs(gs), gi_int(gi), reqDataRate(dataRate), result(0), error(0){
    //some codes
}

In CentralEntity.h :

#include "RatePrediction.h"
class CentralEntity : public cAsyncModule
{ 
//friend classes ....
protected:
  virtual void initialize();
}

In CentralEntity.cc:

#include "RatePrediction.h"

void CentralEntity::initialize()
{
RatePrediction RateObj(1.1e-13,1.2-13,1e4);
}

EDIT:

@hildensia Thanks for your comment. I actually did this and now it works. But I am not sure if it can be reliable and stable or not.

I edited the Makefile manually and I added:

OBJS= RatePrediction.o

RatePrediction.o: RatePrediction.cc
    $(CXX) -c $(COPTS) RatePrediction.cc
Était-ce utile?

La solution

The problem lies within the compilation. RatePrediction.cc seems to be not compiled at all. Thus the linker can't find the Constructor, because there is no object file with it. Your solution in the Makefile seems to be appropriate for now, but will probably be overwritten by your build system. So you should gather information about how you can define which files should be build by Eclipse.

Autres conseils

You should define the construction function of Class RatePrediction in RatePrediction.h file. and it may be better to add such lines "#ifndef *_H #define *_H #endif" in every *.h files.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top