我有一个类,我希望其中一个类函数接受一个向量并返回一个不同的向量。我试过这样的事情,但我在函数声明和定义中得到错误,说它们不匹配。
错误信息:
example.cpp:11:18: error: prototype for ‘std::vector<int> myClass::myFunction(std::vector<double>&)’ does not match any in class ‘myClass’
std::vector<int> myClass::myFunction(std::vector<dataType> & myVector){
^
example.cpp:8:22: error: candidate is: std::vector<int> myClass::myFunction(const std::vector<double>&)
std::vector<int> myFunction(const std::vector<dataType> & );
实际代码:
#include<vector>
#include<iostream>
typedef double dataType;
class myClass{
public:
std::vector<int> myFunction(const std::vector<dataType> & );
};
std::vector<int> myClass::myFunction(std::vector<dataType> & myVector){
std::vector<int> results;
results.resize(myVector.size());
for(int i=0; i<results.size(); ++i){
results[i] = 0;
}
return results;
}
int main(){
return 0;
}
根据错误信息,函数是
SetParallel::checkElements(std::vector<double>&)
原型是
SetParallel::checkElements(const std::vector<double>&)
(const std::vector<int>&
两种情况都省略了首字母)
你能看到区别么?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句