我有一个仿函数基类和一个仿函数派生类,如下所示:
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;
};
我正在创建它:
ReadSensor *rs = new ReadSensorDummy(5);
它编译,但我收到以下链接错误:
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
怎么了?不需要 dynamic_cast,但我确实尝试过,但没有帮助。