Reputation: 67
I'm trying to boost bind a particular function for use later, the following code is what throws a compile error the first function is the one I'm trying to bind to generate a boost function, the second statement is the actual bind statement, the third statement is the function inside which this bind statement is written and finally there are the errors:
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)
and the bind looks like this
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);
inside this function
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);
I'm using C++14 and gcc 7.4.0.
Edit: This worked
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);
};
If someone could explain why this works and not the former? Thanks!
Upvotes: 0
Views: 730
Reputation: 67
Someone pointed me to the answer, it's that boost::bind can take 9 arguments at max and I have ten including the class pointer.
Upvotes: 2