Hello:
Here is what I'm going for; maybe this will explain
I have the following code in my project:
AddOlc("name", "Please enter the name of the object", STRING,
boost::bind(OlcString, _1, _2, _3, boost::bind(&Entity::GetName, this),
boost::bind(&Entity::SetName, this, _1)));
OlcString:
void OlcString(Entity* ed, Player* mob, const Variant* input,
boost::function get, boost::function set)
{
if (input->Typeof() != VAR_STR)
{
mob->Message(MSG_ERROR, "Invalid input.");
return;
}
set(input->GetStr());
}
The point is for the callback (OlcString) to use the setter to set the
name of the object, which is not what is happening.
Here are the compile erorrs:
12:19:26: Compiling entity.cpp.
In file included from /usr/local/include/boost/bind.hpp:22:0,
from entity.cpp:5:
/usr/local/include/boost/bind/bind.hpp: In member function ‘void
boost::_bi::list5::operator()(boost::_bi::type<void>, F&, A&, int) [with F = void
(*)(Entity*, Player*, const Variant*,
boost::function, boost::function), A = boost::_bi::list3, A1 = boost::arg<1>, A2 = boost::arg<2>, A3 =
boost::arg<3>, A4 = boost::_bi::bind_t,
boost::_bi::list1 > >, A5 =
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > >]’:
/usr/local/include/boost/bind/bind_template.hpp:116:59: instantiated
from ‘boost::_bi::bind_t::result_type boost::_bi::bind_t::operator()(A1&, A2&, A3&) [with A1 = Entity*, A2 = Player*, A3 =
const Variant*, R = void, F = void (*)(Entity*, Player*, const Variant*,
boost::function, boost::function), L = boost::_bi::list5,
boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > >, boost::_bi::bind_t::result_type = void]’
/usr/local/include/boost/function/function_template.hpp:153:11:
instantiated from ‘static void
boost::detail::function::void_function_obj_invoker3::invoke(boost::detail::function::function_buffer&, T0, T1, T2)
[with FunctionObj = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*]’
/usr/local/include/boost/function/function_template.hpp:907:60:
instantiated from ‘void boost::function3::assign_to(Functor) [with Functor = boost::_bi::bind_t, boost::function), boost::_bi::list5,
boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*]’
/usr/local/include/boost/function/function_template.hpp:722:7:
instantiated from ‘boost::function3::function3(Functor,
typename
boost::enable_if_c::value,
int>::type) [with Functor = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*, typename
boost::enable_if_c::value,
int>::type = int]’
/usr/local/include/boost/function/function_template.hpp:1042:16:
instantiated from ‘boost::function::function(Functor,
typename
boost::enable_if_c::value,
int>::type) [with Functor = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*, typename
boost::enable_if_c::value,
int>::type = int]’
entity.cpp:27:177: instantiated from here
/usr/local/include/boost/bind/bind.hpp:525:9: error: conversion from
‘boost::_bi::result_traits&>
::type’ to non-scalar type ‘boost::function’ requested
/usr/local/include/boost/bind/bind.hpp: In member function ‘void
boost::_bi::list2::operator()(boost::_bi::type<void>, F&, A&,
int) [with F = boost::_mfi::mf1, A = const boost::_bi::list3, A1 = boost::_bi::value, A2 =
boost::arg<1>]’:
/usr/local/include/boost/bind/bind_template.hpp:318:59: instantiated
from ‘boost::_bi::bind_t::result_type boost::_bi::bind_t::eval(A&) [with A = const boost::_bi::list3, R = void, F = boost::_mfi::mf1, L =
boost::_bi::list2, boost::arg<1> >,
boost::_bi::bind_t::result_type = void]’
/usr/local/include/boost/bind/bind.hpp:376:136: instantiated from
‘typename boost::_bi::result_traits::type boost::_bi::list3::operator[](boost::_bi::bind_t&) const [with R = void,
F = boost::_mfi::mf1, L =
boost::_bi::list2, boost::arg<1> >, A1 =
Entity*&, A2 = Player*&, A3 = const Variant*&, typename
boost::_bi::result_traits::type = void]’
/usr/local/include/boost/bind/bind.hpp:525:9: instantiated from ‘void
boost::_bi::list5::operator()(boost::_bi::type<void>, F&, A&, int) [with F = void
(*)(Entity*, Player*, const Variant*,
boost::function, boost::function), A = boost::_bi::list3, A1 = boost::arg<1>, A2 = boost::arg<2>, A3 =
boost::arg<3>, A4 = boost::_bi::bind_t,
boost::_bi::list1 > >, A5 =
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > >]’
/usr/local/include/boost/bind/bind_template.hpp:116:59: instantiated
from ‘boost::_bi::bind_t::result_type boost::_bi::bind_t::operator()(A1&, A2&, A3&) [with A1 = Entity*, A2 = Player*, A3 =
const Variant*, R = void, F = void (*)(Entity*, Player*, const Variant*,
boost::function, boost::function), L = boost::_bi::list5,
boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > >, boost::_bi::bind_t::result_type = void]’
/usr/local/include/boost/function/function_template.hpp:153:11:
instantiated from ‘static void
boost::detail::function::void_function_obj_invoker3::invoke(boost::detail::function::function_buffer&, T0, T1, T2)
[with FunctionObj = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*]’
/usr/local/include/boost/function/function_template.hpp:907:60:
instantiated from ‘void boost::function3::assign_to(Functor) [with Functor = boost::_bi::bind_t, boost::function), boost::_bi::list5,
boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*]’
/usr/local/include/boost/function/function_template.hpp:722:7:
instantiated from ‘boost::function3::function3(Functor,
typename
boost::enable_if_c::value,
int>::type) [with Functor = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*, typename
boost::enable_if_c::value,
int>::type = int]’
/usr/local/include/boost/function/function_template.hpp:1042:16:
instantiated from ‘boost::function::function(Functor,
typename
boost::enable_if_c::value,
int>::type) [with Functor = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*, typename
boost::enable_if_c::value,
int>::type = int]’
entity.cpp:27:177: instantiated from here
/usr/local/include/boost/bind/bind.hpp:313:9: error: no match for call
to ‘(boost::_mfi::mf1)
(Entity*&, Entity*&)’
/usr/local/include/boost/bind/mem_fn_template.hpp:163:7: note:
candidates are: R boost::_mfi::mf1::operator()(T*, A1) const
[with R = void, T = Entity, A1 = const std::basic_string<char>&]
/usr/local/include/boost/bind/mem_fn_template.hpp:184:7: note: R
boost::_mfi::mf1::operator()(T&, A1) const [with R = void, T =
Entity, A1 = const std::basic_string<char>&]
In file included from
/usr/local/include/boost/function/detail/maybe_include.hpp:13:0,
from /usr/local/include/boost/function/detail/function_iterate.hpp:14,
from
/usr/local/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
from /usr/local/include/boost/function.hpp:64,
from mud.h:4,
from entity.h:10,
from entity.cpp:6:
/usr/local/include/boost/function/function_template.hpp: In static
member function ‘static R
boost::detail::function::function_obj_invoker0::invoke(boost::detail::function::function_buffer&) [with FunctionObj
= std::basic_string<char>, R = std::basic_string<char>]’:
/usr/local/include/boost/function/function_template.hpp:907:60:
instantiated from ‘void boost::function0<R>::assign_to(Functor) [with
Functor = std::basic_string<char>, R = std::basic_string<char>]’
/usr/local/include/boost/function/function_template.hpp:722:7:
instantiated from ‘boost::function0<R>::function0(Functor, typename
boost::enable_if_c::value,
int>::type) [with Functor = std::basic_string<char>, R =
std::basic_string<char>, typename
boost::enable_if_c::value,
int>::type = int]’
/usr/local/include/boost/function/function_template.hpp:1042:16:
instantiated from ‘boost::function::function(Functor, typename
boost::enable_if_c::value,
int>::type) [with Functor = std::basic_string<char>, R =
std::basic_string<char>, typename
boost::enable_if_c::value,
int>::type = int]’
/usr/local/include/boost/bind/bind.hpp:525:9: instantiated from ‘void
boost::_bi::list5::operator()(boost::_bi::type<void>, F&, A&, int) [with F = void
(*)(Entity*, Player*, const Variant*,
boost::function, boost::function), A = boost::_bi::list3, A1 = boost::arg<1>, A2 = boost::arg<2>, A3 =
boost::arg<3>, A4 = boost::_bi::bind_t,
boost::_bi::list1 > >, A5 =
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > >]’
/usr/local/include/boost/bind/bind_template.hpp:116:59: instantiated
from ‘boost::_bi::bind_t::result_type boost::_bi::bind_t::operator()(A1&, A2&, A3&) [with A1 = Entity*, A2 = Player*, A3 =
const Variant*, R = void, F = void (*)(Entity*, Player*, const Variant*,
boost::function, boost::function), L = boost::_bi::list5,
boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > >, boost::_bi::bind_t::result_type = void]’
/usr/local/include/boost/function/function_template.hpp:153:11:
instantiated from ‘static void
boost::detail::function::void_function_obj_invoker3::invoke(boost::detail::function::function_buffer&, T0, T1, T2)
[with FunctionObj = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*]’
/usr/local/include/boost/function/function_template.hpp:907:60:
instantiated from ‘void boost::function3::assign_to(Functor) [with Functor = boost::_bi::bind_t, boost::function), boost::_bi::list5,
boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*]’
/usr/local/include/boost/function/function_template.hpp:722:7:
instantiated from ‘boost::function3::function3(Functor,
typename
boost::enable_if_c::value,
int>::type) [with Functor = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*, typename
boost::enable_if_c::value,
int>::type = int]’
/usr/local/include/boost/function/function_template.hpp:1042:16:
instantiated from ‘boost::function::function(Functor,
typename
boost::enable_if_c::value,
int>::type) [with Functor = boost::_bi::bind_t,
boost::function),
boost::_bi::list5, boost::arg<2>, boost::arg<3>,
boost::_bi::bind_t,
boost::_bi::list1 > >,
boost::_bi::bind_t, boost::_bi::list2,
boost::arg<1> > > > >, R = void, T0 = Entity*, T1 = Player*, T2 = const
Variant*, typename
boost::enable_if_c::value,
int>::type = int]’
entity.cpp:27:177: instantiated from here
/usr/local/include/boost/function/function_template.hpp:132:42: error:
no match for call to ‘(std::basic_string<char>) ()’
make: *** [entity.o] Error 1
Thanks in advance,
Ty
On 4/11/2011 12:12 PM, Steven Watanabe wrote:
AMDG
On 04/11/2011 10:44 AM, Littlefield, Tyler wrote:
I have a quick question regarding boost::bind, as the subject line says.
This isn't a very viable example, but it works well enough to show what
I want.
I have a callback I am using boost::bind to bind to, and I am passing a
function object in as shown by the following code:
#include <cstdio>
#include
#include
class Math
{
public:
void Add(int a, int b, int c, boost::function printer);
{
printer(a+b+c);
}
};
void Printer(int p)
{
printf("%d\n", p);
}How might I make this work? I am not sure how I can pass that as the
fourth argument so that the function can be called like (1,2,3) etc.
Also, in the actual problem I moved the function object to the first
argument, (which just ment changing the prototype and actual function),
but I still got errors.
I'm not sure exactly what you're trying to do,
but the following should work:
boost::bind(&Math::Add, Math(), _1, _2, _3, &Printer)(1, 2, 3)
In Christ,
Steven Watanabe
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
--
Thanks,
Ty