我正在尝试增强绑定特定功能以供以后使用,以下代码引发编译错误,第一个函数是我试图绑定以生成增强功能的函数,第二个语句是实际的bind语句,第三个语句是在其中写入该bind语句的函数,最后出现错误:
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);
};
如果有人可以解释为什么这样做而不是为什么?谢谢!
答案 0 :(得分:0)
有人向我指出了答案,那就是boost :: bind最多可以接受9个参数,而我包括类指针在内就有10个。