0
我在下面指示的行出現錯誤: 當我嘗試返回結構向量時出現此錯誤。我使用了一個模板來返回這些向量。我不是我的錯誤所在。如果我不使用模板,請將返回類型設置爲向量。當返回C++中的結構向量時,沒有匹配函數調用[class]
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;
};
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.
}