1

我有一个仿函数基类和一个仿函数派生类,如下所示:

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,但我确实尝试过,但没有帮助。

4

1 回答 1

5

您已声明打算为 定义构造函数ReadSensor,但编译器未在您的任何源文件中找到定义的构造函数。您可以尝试定义一个空的,或删除声明。

于 2012-10-26T23:46:53.557 回答