当Boost ::绑定模板函数时,模板参数扣除/替换失败
template argument deduction/substitution failed, when boost::binding a templated function
我正在尝试提高绑定特定函数以供以后使用,以下代码是抛出编译错误的是,第一个函数是我要绑定的函数以生成增强功能函数,第二个语句是实际的绑定语句,第三个语句是编写此绑定语句的函数,最后有错误:
template <typename T>
void ValidOperation::CheckDoubleBound(
diagnostic_updater::DiagnosticStatusWrapper& stat,
const std::string& name,
const T& variable_instance,
T upper_bound_value,
T lower_bound_value,
const SeverityLevel severity,
const std::string& message_success,
const std::string& message_lower_fail,
const std::string& message_upper_fail)
和绑定看起来像这样
auto func = boost::bind(&ValidOperation::CheckDoubleBound<T>,
this,
_1,
name,
boost::cref(variable_instance),
upper_bound_value,
lower_bound_value,
severity,
message_success,
message_upper_fail,
message_lower_fail);
此功能内部
template <typename T>
void ValidOperation::AddDoubleBoundConstraint(
const std::string& name,
const T& variable_instance,
const T upper_bound_value,
const T lower_bound_value,
const SeverityLevel severity,
const std::string& message_success,
const std::string& message_lower_fail,
const std::string& message_upper_fail)
In instantiation of ‘void triton::ValidOperation::AddDoubleBoundConstraint(const string&, const T&, T, T, triton::SeverityLevel, const string&, const string&, const string&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>]’:
/home/test/src/ValidOperation.cpp:188:42: required from here
/home/test/src/ValidOperation.cpp:150:28: error: no matching function for call to ‘bind(<unresolved overloaded function type>, triton::ValidOperation*, const boost::arg<1>&, const string&, const boost::reference_wrapper<const double>, const double&, const double&, const triton::SeverityLevel&, const string&, const string&, const string&)’
auto func = boost::bind(&ValidOperation::CheckDoubleBound<T>,
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this,
~~~~~
_1,
~~~
name,
~~~~~
boost::cref(variable_instance),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
upper_bound_value,
~~~~~~~~~~~~~~~~~~
lower_bound_value,
~~~~~~~~~~~~~~~~~~
severity,
~~~~~~~~~
message_success,
~~~~~~~~~~~~~~~~
message_upper_fail,
~~~~~~~~~~~~~~~~~~~
message_lower_fail);
~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/boost/bind.hpp:22:0,
from /opt/ros/melodic/include/ros/publisher.h:35,
from /opt/ros/melodic/include/ros/node_handle.h:32,
from /opt/ros/melodic/include/diagnostic_updater/diagnostic_updater.h:42,
from /home/test/include/triton/ValidOperation.h:23,
from /home/test/src/ValidOperation.cpp:17:
/usr/include/boost/bind/bind.hpp:1875:5: note: candidate: template<class R, class F> boost::_bi::bind_t<R, F, boost::_bi::list0> boost::bind(F)
BOOST_BIND(F f)
^
/usr/include/boost/bind/bind.hpp:1875:5: note: template argument deduction/substitution failed:
/home/src/ValidOperation.cpp:150:28: note: candidate expects 1 argument, 11 provided
auto func = boost::bind(&ValidOperation::CheckDoubleBound<T>,
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this,
~~~~~
_1,
~~~
name,
~~~~~
boost::cref(variable_instance),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
upper_bound_value,
~~~~~~~~~~~~~~~~~~
lower_bound_value,
~~~~~~~~~~~~~~~~~~
severity,
~~~~~~~~~
message_success,
~~~~~~~~~~~~~~~~
message_upper_fail,
~~~~~~~~~~~~~~~~~~~
message_lower_fail);
我正在使用C 14和GCC 7.4.0。
编辑:这起作用
auto func = [this,
name,
variable_instance,
upper_bound_value,
lower_bound_value,
severity,
message_success,
message_lower_fail,
message_upper_fail](
diagnostic_updater::DiagnosticStatusWrapper& stat) {
this->CheckDoubleBound<T>(stat,
name,
variable_instance,
upper_bound_value,
lower_bound_value,
severity,
message_success,
message_lower_fail,
message_upper_fail);
};
如果有人可以解释为什么这有效而不是前者?谢谢!
有人向我指出了答案,这就是boost :: bind可以在最大的情况下进行9个参数,而我有十个包括类指针。
https://www.boost.org/doc/libs/1_66_0/libs/bind/doc/doc/html/bind.html#bind.implementation.number_of_arguments
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- variadic模板中的模板参数推导失败
- 当给定默认值时,为什么此模板参数推导失败
- 模板参数推导失败,函数参数/参数不匹配
- 为什么模板参数推导失败?
- 嵌套参数包扩展失败
- 模板参数的 C++ 自动模板推导失败
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 失败,出现错误 87:参数不正确.如何判断哪个参数不正确?
- 在 g++ 6.2.1 中将参数包转发到 constructor() 失败
- 当变量和参数名称匹配时,移动语义构造失败
- 作为模板参数的成员函数指针在继承的成员函数上失败,如何以及为什么?
- 模板参数推导/替换失败,lambda作为函数指针
- 调用基函数时模板参数推导失败
- 类模板参数推导失败会导致替换失败
- 折叠表达式模板参数推导/替换失败
- 结果失败或多个参数无效