一個基類我有一個仿函數的基類和仿函數派生類,看起來像這樣:仿函數在C++
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)" ([email protected]@[email protected]) referenced in function "public: __cdecl ReadSensorDummy::ReadSensorDummy(int)" ([email protected]@[email protected]@Z) W:\SafetySystemTest.obj
什麼問題?一個dynamic_cast不應該是需要的,但我確實嘗試過,並沒有幫助。
如果你所有的類都提供了一個() - > int函子,爲什麼不使用std :: function? typedef std :: function ReadSensor; ReadSensor MakeReadSensorDummy(int x){return [x](){return x; }}或ReadSensor MakeComplexSensor(){ComplexState x; return [x](){return x.calculate(); }} ... –
Yakk