C++ 在c+;中返回结构向量时,没有用于调用[class]的匹配函数+;

C++ 在c+;中返回结构向量时,没有用于调用[class]的匹配函数+;,c++,C++,我在下面指示的行中得到一个错误: 当我试图返回一个结构向量时,我得到了这个错误。我使用了一个模板来返回这些向量。我不知道我的错误在哪里。如果不使用模板,请将返回类型设置为vector Header File: typedef unsigned long ulong_t; class Tool { public: Tool(); void toolInterface(); void run(); private: ifstream allDevicesFile; struct devS

我在下面指示的行中得到一个错误: 当我试图返回一个结构向量时,我得到了这个错误。我使用了一个模板来返回这些向量。我不知道我的错误在哪里。如果不使用模板,请将返回类型设置为vector

Header File:

typedef unsigned long ulong_t;
class Tool {
public:
    Tool();
void toolInterface();
void run();
private:

ifstream allDevicesFile;
struct devStats {
    //structure variables,
};
template<class devStats>
vector<devStats> readDev();
vector<devStats> stats;
string fileNameAll;
Report report;
Commandline cmd;
Configuration conf;
Devices dev;
};
头文件:
typedef无符号长ulong\t;
类工具{
公众:
工具();
void toolInterface();
无效运行();
私人:
ifstream所有设备文件;
结构devStats{
//结构变量,
};
样板
向量readDev();
矢量统计;
字符串fileNameAll;
报告;
命令行命令;
配置配置;
设备开发;
};
Tool.cpp:

Tool::Tool() {
fileNameAll = "/proc/diskstats";
    allDevicesFile.open((char*)fileNameAll.c_str());
    if (allDevicesFile.fail()) {
        cout << "Could not open /proc/diskstats\n";
    }// TODO Auto-generated constructor stub

}
template<class devStats>
vector<devStats> Tool::readDev() {
devStats dev;
while (!allDevicesFile.eof()) {
    allDevicesFile >> dev.decoy1;
    allDevicesFile >> dev.decoy2;
    allDevicesFile >> dev.devName;
    allDevicesFile >> dev.reads;
    allDevicesFile >> dev.readMerge;
    allDevicesFile >> dev.writes;
    allDevicesFile >> dev.secReading;
    allDevicesFile >> dev.mSecondsRead;
    allDevicesFile >> dev.writeCompleted;
    allDevicesFile >> dev.secWritting;
    allDevicesFile >> dev.mSecondWrite;
    allDevicesFile >> dev.currentI_O;
    allDevicesFile >> dev.mSecondsI_O;
    allDevicesFile >> dev.weightedI_O;
    dev.mSecondsRead = dev.mSecondsRead / 1000;
    dev.mSecondWrite = dev.mSecondWrite / 1000;
    dev.mSecondsI_O = dev.mSecondsI_O / 1000;
    stats.push_back(dev);
}
cout << stats[0].devName;
return stats;
}

void Tool::run() {
stats = readDev(); //error occurs here.
}
Tool::Tool(){
fileNameAll=“/proc/diskstats”;
打开((char*)fileNameAll.c_str());
if(allDeviceFile.fail()){
cout>dev.decoy1;
所有设备文件>>dev.decoy2;
AllDeviceFile>>dev.devName;
AllDeviceFile>>dev.reads;
AllDeviceFile>>dev.readMerge;
AllDeviceFile>>dev.writes;
所有设备文件>>dev.secReading;
所有设备文件>>dev.mSecondsRead;
所有设备文件>>dev.writeCompleted;
所有设备文件>>dev.secwriting;
AllDeviceFile>>dev.mSecondWrite;
所有设备文件>>dev.current i_O;
所有设备文件>>dev.mSecondsI\O;
所有设备文件>>dev.weightedI\u O;
dev.mSecondsRead=dev.mSecondsRead/1000;
dev.mSecondWrite=dev.mSecondWrite/1000;
dev.mSecondsI_O=dev.mSecondsI_O/1000;
统计数据。推回(开发);
}

CUT

普通过载解决方案不考虑返回类型。返回类型与任何类型不匹配。因此模板参数无法自动解决。

作为一个实际的解决方案,只需删除模板化


有一种特殊情况,即仅用作返回类型的模板参数可以由调用上下文解析,这是针对转换运算符的