没有匹配的调用函数
No matching function for call?
我不知道为什么我得到这个错误:
error: no matching function for call to ‘write_vector(int&)’
template <typename T>
void write_vector(const vector<T>& V)
{
cout << "The numbers in the vector are: " << endl;
for(int i=0; i < V.size(); i++)
cout << V[i] << " ";
}
int main()
{
int input;
vector<int> V;
cout << "Enter your numbers to be evaluated: " << endl;
cin >> input;
V.push_back(input);
write_vector(input);
return 0;
}
Write
write_vector(V); //V is std::vector<int>
代替
write_vector(input); //input is int
请尝试理解错误信息。它提供了很多提示,告诉你代码中哪里出了问题。
而且,你似乎在代码的某个地方写了using namespace std
。不要那样做。把那条线擦掉。然后用std::vector
代替vector
。这是一种较好的编码方式,可以避免using namespace std
带来的许多问题,特别是在大型项目中。
将输入变量传递给函数,模板函数需要一个向量。试着用V代替
使用错误的形参调用write_vector函数。在您刚刚发布的代码中,您正在使用'input'作为参数调用过程,但'input'是'int'类型而不是'vector'。
相关文章:
- 如何用参数值调用函数(仅在运行时已知)
- 从python中调用C++函数并获取返回值
- 当使用通配符和null指针调用函数时,对输出的说明
- 从R调用C++函数并对其进行集成时出错
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- 如何在qt中从另一个类调用函数
- 在 COUT 语句中使用 COUT 调用函数
- 如何从线程中的不同模块调用函数?
- C++从函数指针数组调用函数
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- 如何在 C/C++ 中从外部库调用函数
- 如何使用运算符在同一行中多次调用函数
- 是否可以创建一个从不同类调用函数的线程?
- 无法为类成员调用函数
- 如何从另一个标头 c++ 调用函数
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 如何只允许在调用函数 B 后调用函数 A?
- 我可以这样调用函数吗?
- 如何在 c++ 的类中递归调用函数方法?
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?