我有一个带有纯虚方法的类模板:
OneWireSensor.h:
template <typename T>
class OneWireSensor {
public:
OneWireSensor(std::string OneWireFilePath) : FileName(OneWireFilePath + "/w1_slave") {};
virtual T Read() = 0;
virtual ~OneWireSensor() {};
protected:
string w1_slave()
{
...
}
private:
const string FileName;
};
我有一个子类,它实现了纯虚方法:
DS18B20.h:
#include <map>
#include "OneWireSensor.h"
class DS18B20 : public OneWireSensor<double>
{
public:
DS18B20(std::string OneWireFilePath);
virtual ~DS18B20();
virtual double Read();
static std::map<string, DS18B20> ReadConnectedSensors(std::string OneWireBasePath);
};
DS18B20.cpp:
#include <iostream>
#include <string>
#include <dirent.h>
#include <stdio.h>
#include "DS18B20.h"
DS18B20::DS18B20(std::string OneWireFilePath) : OneWireSensor(OneWireFilePath)
{ }
DS18B20::~DS18B20()
{ }
double DS18B20::Read()
{
string token = "t=";
string flash = this->w1_slave();
size_t pos = flash.find(token);
size_t nl = flash.find("\n", pos+1);
string temperature = flash.substr(pos + token.length(), nl);
double retVal = std::stod(temperature);
return retVal/1000;
}
std::map<string, DS18B20> DS18B20::ReadConnectedSensors(std::string OneWireBasePath)
{
...
}
现在我的问题: 我使用的是Gnu Toolchain for Raspberry from SysProgs,效果很好。此代码也编译和链接没有任何问题。
但Eclipse CDT告诉我: 类型&#39; DS18B20&#39;必须实现继承的纯虚方法&#39; OneWireSensor :: Read&#39;
在main.cpp的这一行:
DS18B20 Sensor("/sys/bus/w1/devices/28-000004027c9f");
我不想为此类错误禁用CDT解析器。我想让CDT解析器正确检测实现。
有什么想法吗?