I have a functor base class and a functor derived class that looks like this:
class ReadSensor
{
public:
ReadSensor();
virtual ~ReadSensor(void){}
virtual int operator()(void) = 0;
};
class ReadSensorDummy : public ReadSensor
{
public:
ReadSensorDummy() : x(0) {}
ReadSensorDummy(int x): x(x) {}
~ReadSensorDummy(void) {}
int operator() (void) { return x;}
private:
int x;
};
I am creating it as so:
ReadSensor *rs = new ReadSensorDummy(5);
It compiles, but I get the following link error:
Error 2 error LNK2019: unresolved external symbol "public: __cdecl ReadSensor::ReadSensor(void)" (??0ReadSensor@@QEAA@XZ) referenced in function "public: __cdecl ReadSensorDummy::ReadSensorDummy(int)" (??0ReadSensorDummy@@QEAA@H@Z) W:\SafetySystemTest.obj
What is wrong? A dynamic_cast shouldn’t be needed, but I did try it and it didn’t help.
You have declared the intention to define a constructor for
ReadSensor, but the compiler did not find one defined in any of your source files. You can try defining an empty one, or removing the declaration.