嘿,我通常使用 Javascript 和 dart,但我被要求为某些项目用 C++ 编写一些代码,所以我在编写代码时遇到了很多问题。我遇到了这个错误,我花了几个小时试图解决这个错误,但没有任何线索,我最终决定来这里寻求帮助。
首先,我有一个通用函数,它可以根据作为参数传递给它的函数的参数创建一个元组。
template <typename R, typename... T>
tuple<T...> function_args(R (*)(T...))
{
return tuple<T...>();
}
Run Code Online (Sandbox Code Playgroud)
但是每当我传递一个以向量作为参数的函数时,它就会抛出错误
/tmp/ViPPynah0U.cpp: In instantiation of 'void function_args(R (*)(T ...)) [with R = int; T = {std::vector<int, std::allocator<int> >&, int}]':
/tmp/ViPPynah0U.cpp:33:18: required from here
/tmp/ViPPynah0U.cpp:23:17: error: no matching function for call to 'std::tuple<std::vector<int, std::allocator<int> >&, int>::tuple()'
Run Code Online (Sandbox Code Playgroud)
这是用于进一步说明的完整示例代码,
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int example(vector<int> &nums, int target)
{
return 0;
}
template <typename R, …Run Code Online (Sandbox Code Playgroud)