Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 该类型必须实现继承的纯虚拟模板方法_C++_Eclipse_Templates_Eclipse Cdt_Pure Virtual - Fatal编程技术网

C++ 该类型必须实现继承的纯虚拟模板方法

C++ 该类型必须实现继承的纯虚拟模板方法,c++,eclipse,templates,eclipse-cdt,pure-virtual,C++,Eclipse,Templates,Eclipse Cdt,Pure Virtual,我有一个带有纯虚拟方法的类模板: OneWireSensor.h: template <typename T> class OneWireSensor { public: OneWireSensor(std::string OneWireFilePath) : FileName(OneWireFilePath + "/w1_slave") {}; virtual T Read() = 0; virtual ~OneWireSensor() {}; prote

我有一个带有纯虚拟方法的类模板:

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;
};
模板
一类线传感器{
公众:
OneWireSensor(std::string OneWireFilePath):文件名(OneWireFilePath+“/w1_slave”){};
虚拟T Read()=0;
虚拟~OneWireSensor(){};
受保护的:
字符串w1_slave()
{
...
}
私人:
常量字符串文件名;
};
我有一个子类,它实现了纯虚拟方法:

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);
};
#包括
#包括“OneWireSensor.h”
DS18B20类:公共单线传感器
{
公众:
DS18B20(标准::字符串OneWireFilePath);
虚拟的~DS18B20();
虚拟双读();
静态std::map 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)
{
  ...
}
#包括
#包括
#包括
#包括
#包括“DS18B20.h”
DS18B20::DS18B20(标准::字符串OneWireFilePath):OneWireSensor(OneWireFilePath)
{ }
DS18B20::~DS18B20()
{ }
双DS18B20::Read()
{
字符串标记=“t=”;
字符串flash=this->w1_slave();
大小\u t pos=flash.find(令牌);
大小\u t nl=闪存。查找(“\n”,位置+1);
字符串温度=flash.substr(pos+token.length(),nl);
双回程=std::stod(温度);
返回返回值/1000;
}
std::map DS18B20::ReadConnectedSensors(std::string OneWireBasePath)
{
...
}
现在我的问题是: 我正在使用,效果很好。而且这段代码的编译和链接没有任何问题

但Eclipse CDT告诉我: 类型“DS18B20”必须实现继承的纯虚拟方法“OneWireSensor::Read”

在main.cpp中的这一行:
DS18B20传感器(“/sys/bus/w1/devices/28-000004027c9f”)

我不想为此类错误禁用CDT解析器。我想让CDT解析器正确地检测实现


有什么想法吗?

如果你这么做了怎么办<代码>虚拟双OneWireSensor::Read()
虚拟双onewire传感器::Read()不可编译。但在我撤销了这些更改之后,eclipse不再显示这个错误。所以我认为这只是一个刷新错误,eclipse在重新启动时保存了这个错误。。。非常感谢你的帮助!不过对我来说是可以编译的。使用Visual Studio 2013。如果这样做会怎么样<代码>虚拟双OneWireSensor::Read()
虚拟双onewire传感器::Read()不可编译。但在我撤销了这些更改之后,eclipse不再显示这个错误。所以我认为这只是一个刷新错误,eclipse在重新启动时保存了这个错误。。。非常感谢你的帮助!不过对我来说是可以编译的。使用Visual Studio 2013。