C++ uld解释为什么这是有效的而不是前者?谢谢
有人告诉我答案,boost::bind最多可以接受9个参数,包括类指针在内,我有10个参数C++ uld解释为什么这是有效的而不是前者?谢谢,c++,c++11,templates,boost,bind,C++,C++11,Templates,Boost,Bind,有人告诉我答案,boost::bind最多可以接受9个参数,包括类指针在内,我有10个参数 我不是boost bind的专家(只使用过几次),但为什么您的模板是一个参考?(在boost::bind(&ValidOperation::CheckDoubleBound)中)以下变量:boost::cref(variable_instance)、upper_bound_value、lower_bound_value都是同一类型的吗?是的,这三个变量是同一类型的。我不是在这里调用函数,只是为以后的调用创
我不是boost bind的专家(只使用过几次),但为什么您的模板是一个参考?(在boost::bind(&ValidOperation::CheckDoubleBound)中)以下变量:
boost::cref(variable_instance)、upper_bound_value、lower_bound_value
都是同一类型的吗?是的,这三个变量是同一类型的。我不是在这里调用函数,只是为以后的调用创建它。
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);
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);
};