Я пытаюсь повысить привязку конкретной функции для использования позже, следующий код - это то, что выдает ошибку компиляции, первая функция - это та, которую я пытаюсь связать, чтобы сгенерировать функцию повышения, второе утверждение - фактическоеоператор связывания, третий оператор - это функция, внутри которой написан этот оператор связывания, и, наконец, появляются ошибки:
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);
};
Если кто-то может объяснить, почемуэто работает а не бывший?Спасибо!