"No Matching Function for call"错误
"No Matching Function for call" Error
我正在做这个项目,我必须将文件中的输入放入向量中,然后将该向量分解并将其元素发送到类中。我正在尝试构建班级人员的测试,但是当我尝试这样做时,我遇到了此错误。
错误:
C:UsersEricDropboxCSE 2122 - C++Project FilesHomework09main.cpp:57: error: no matching function for call to `person::person(int, std::vector<int, std::allocator<int> >&)'
C:UsersEricDropboxCSE 2122 - C++Project FilesHomework09main.cpp:9: note: candidates are: person::person(const person&)
C:UsersEricDropboxCSE 2122 - C++Project FilesHomework09main.cpp:17: note: person::person(int, std::vector<float, std::allocator<float> >)
主.cpp
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
/* Person Class */
class person
{
public:
int id;
vector <float> scores;
float averageScore;
/* Person Constructor */
person(int _id, vector<float> _scores)
{
id = _id;
scores = _scores;
int total;
for(unsigned int i = 0; i < _scores.size(); i++)
{
total += _scores[i];
}
averageScore = (total / _scores.size());
}
};
/* Function Prototypes */
string getFileName();
void readFile(string fileName, vector <int> &tempVec);
/* Main */
int main()
{
vector <int> tempVec;
vector <int> tempVec2;
tempVec2.push_back(56);
tempVec2.push_back(98);
tempVec2.push_back(78);
tempVec2.push_back(89);
int personCount = 0;
vector <person> personVector;
string fileName = getFileName();
readFile(fileName, tempVec);
personCount = (tempVec.size())/(4);
person eric = person(110, tempVec2);
}
/* getFileName Function */
string getFileName()
{
string fileName;
cout << "Enter the file you wish to read from: ";
cin >> fileName;
return fileName;
}
/* readFile Function */
void readFile(string fileName, vector <int> &tempVec)
{
float x = 0;
ifstream fin;
fin.open(fileName.c_str(), ios::in);
if(!fin.is_open())
{
perror(fileName.c_str());
exit(10);
}
while(!fin.fail())
{
fin >> x;
tempVec.push_back(x);
}
fin.close();
}
有什么想法吗?
您的person
构造函数采用 float
s 的vector
,并且您正在尝试将tempVec2
传递到其中,这是 int
s 的vector
。
相关文章:
- "error: no matching function for call to"构造函数错误
- "no matching function for call to 'Vector::Vector'"错误
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 学习 c++,编译错误"no matching function for call"
- 结构错误:"no matching function for call to "
- 创建函数变体向量时"No matching function for call"错误
- 编译时二叉搜索树错误的反向迭代器表示"no matching function call for operator=()"
- 如果子类中没有构造函数方法,则错误"no matching function for call to 'LGame::LGame(String&)'"
- 提升多精度浮点数128:标准::exp错误:'no matching function for call'
- C++字符串.替换生成"No matching function for call"错误
- "No Matching Function for call"错误
- 重载<运算符在另一个类中使用时"no matching function for call"错误
- C++ "No matching function for call"错误
- 为什么OpenSSL给我一个"called a function you should not call"错误?
- 海湾合作委员会"no matching function for call.."错误
- 模板函数给出"no matching function for call"错误
- Pjsip new-call错误…无法找到默认的音频设备(PJMEDIA_EAUD_NODEFDEV)
- 使用提升::绑定时"no match for call"错误
- C++:莫名其妙"pure virtual function call"错误
- C++中多线程处理时出现"no matching function call"错误