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++ 17标准。_C++_Templates_Variadic Templates - Fatal编程技术网

将成员函数传递给模板函数时出现语法错误 首先,我使用C++ 17标准。

将成员函数传递给模板函数时出现语法错误 首先,我使用C++ 17标准。,c++,templates,variadic-templates,C++,Templates,Variadic Templates,我遇到问题的代码工作正常,除非我尝试在具有相同模板函数的类中使用它 以下代码行: auto t = make_tuple_seq(std::make_index_sequence<numArgs>{}, &lzuint<T, A...>::helper); lzuint::helper是一个非静态成员函数。它需要调用一个对象。对象(成为函数中的this指针)通常作为隐藏的第一个参数传递,因此函数不接受一个参数的消息 有两种方法可以解决这个问题:或者使用l

我遇到问题的代码工作正常,除非我尝试在具有相同模板函数的类中使用它

以下代码行:

    auto t = make_tuple_seq(std::make_index_sequence<numArgs>{}, &lzuint<T, A...>::helper);
lzuint::helper
是一个非静态成员函数。它需要调用一个对象。对象(成为函数中的
this
指针)通常作为隐藏的第一个参数传递,因此函数不接受一个参数的消息

有两种方法可以解决这个问题:或者使用lambdas

auto t = make_tuple_seq(std::make_index_sequence<numArgs>{},
                        [this](size_t i) { return helper(i); });

使用lambdas通常是推荐的解决方案。

最小代码不完整。什么是,例如,
\u func
?请发布实际错误消息和实际代码。对于这个错误,我很抱歉,我已经编辑了问题,将实际代码和我收到的第一个错误都包括在内。您提供的示例非常有效,谢谢。我想我应该在发帖之前有足够的睡眠,因为现在我觉得这很明显。非常感谢!
source.cpp(19): error C2064: term does not evaluate to a function taking 1 arguments
auto t = make_tuple_seq(std::make_index_sequence<numArgs>{},
                        [this](size_t i) { return helper(i); });
auto t = make_tuple_seq(std::make_index_sequence<numArgs>{},
                        std::bind(&lzuint<T, A...>::helper, this, std::placeholders::_1));