Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 调用没有匹配的函数?_C++_Templates_Function - Fatal编程技术网

C++ 调用没有匹配的函数?

C++ 调用没有匹配的函数?,c++,templates,function,C++,Templates,Function,无法理解我为什么会出现此错误: error: no matching function for call to ‘write_vector(int&)’ 模板 无效写入向量(常量向量和V) { 无法将输入变量传递到函数中,模板函数需要一个向量。请尝试传入V insted您调用的是使用错误的参数编写向量函数。在刚刚发布的代码中,您使用“input”作为参数调用过程,但“input”是“int”类型而不是“vector”。write write_vector(V); //V is std:

无法理解我为什么会出现此错误:

error: no matching function for call to ‘write_vector(int&)’
模板
无效写入向量(常量向量和V)
{

无法将输入变量传递到函数中,模板函数需要一个向量。请尝试传入V insted您调用的是使用错误的参数编写向量函数。在刚刚发布的代码中,您使用“input”作为参数调用过程,但“input”是“int”类型而不是“vector”。

write

write_vector(V); //V is std::vector<int>
请尝试理解错误消息。它提供了关于代码中出现错误的大部分提示


另外,您似乎已经在代码中的某个地方使用命名空间std编写了
。不要这样做。删除该行。然后在使用
vector
的地方使用
std::vector
。这是更好的编码样式,可以避免
使用命名空间std
引起的许多问题,尤其是在大型项目中。

eheheheheheheheheheheheheheheh…您是e正在传递整数,但它需要向量。请花1分钟重新阅读您的代码,并思考要传递给
write\u vector
的类型。尝试将模板放置在头文件中。@johnathon:这不是问题所在。@Mat谢谢!我忽略了它。
write_vector(V); //V is std::vector<int>
write_vector(input); //input is int