oHello all: I'm kind of at a loss here. It looks like ther'es an issue with boost::bind somewhere in the mess of 500 templates and 90 screens of errors and I don't know enough about the mess to untangle it. Any info would be awesome. First, the code: sgroup->AddEntry(new OlcStringEntry("name", "Sets the name of the object", OF_NORMAL, boost::bind(&StaticObject::GetName, _1), <159> boost::bind(&StaticObject::SetName, _1, _2))); the 159 I denoted is useful in the errors later. Now the rest of the code I'm using: typedef boost::function<std::string ()> StringGetter; typedef boost::function<void (const std::string&)> StringSetter; class IOlcEntry { protected: std::string _name; std::string _help; FLAG _flag; public: IOlcEntry(const std::string &name, const std::string &help, FLAG flag) { _flag = flag; _name = name; _help = help; } ~IOlcEntry() {} }; class OlcStringEntry:public IOlcEntry { protected: StringGetter _getter; StringSetter _setter; public: OlcStringEntry(const std::string &name, const std::string &help, FLAG flag, const StringGetter getter, const StringSetter setter) :IOlcEntry(name, help, flag) { _setter = setter; _getter = getter; } }; and here is the novel of errors: 02:45:56: Compiling staticObject.cpp. In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp: In instantiation of ‘R boost::_bi::list1<A1>::operator()(boost::_bi::type<R>, F&, A&, long int) [with R = std::basic_string<char>; F = boost::_mfi::cmf0<std::basic_string<char>, BaseObject>; A = boost::_bi::list0; A1 = boost::arg<1>]’: /usr/local/include/boost/bind/bind_template.hpp:20:59: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()() [with R = std::basic_string<char>; F = boost::_mfi::cmf0<std::basic_string<char>, BaseObject>; L = boost::_bi::list1<boost::arg<1> >; boost::_bi::bind_t<R, F, L>::result_type = std::basic_string<char>]’ /usr/local/include/boost/function/function_template.hpp:132:42: required from ‘static R boost::detail::function::function_obj_invoker0<FunctionObj, R>::invoke(boost::detail::function::function_buffer&) [with FunctionObj = boost::_bi::bind_t<std::basic_string<char>, boost::_mfi::cmf0<std::basic_string<char>, BaseObject>, boost::_bi::list1<boost::arg<1> > >; R = std::basic_string<char>]’ /usr/local/include/boost/function/function_template.hpp:934:60: required from ‘void boost::function0<R>::assign_to(Functor) [with Functor = boost::_bi::bind_t<std::basic_string<char>, boost::_mfi::cmf0<std::basic_string<char>, BaseObject>, boost::_bi::list1<boost::arg<1> > >; R = std::basic_string<char>]’ /usr/local/include/boost/function/function_template.hpp:722:7: required from ‘boost::function0<R>::function0(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<std::basic_string<char>, boost::_mfi::cmf0<std::basic_string<char>, BaseObject>, boost::_bi::list1<boost::arg<1> > >; R = std::basic_string<char>; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ /usr/local/include/boost/function/function_template.hpp:1069:16: required from ‘boost::function<R()>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<std::basic_string<char>, boost::_mfi::cmf0<std::basic_string<char>, BaseObject>, boost::_bi::list1<boost::arg<1> > >; R = std::basic_string<char>; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ staticObject.cpp:159:44: required from here /usr/local/include/boost/bind/bind.hpp:243:60: error: no match for ‘operator[]’ in ‘a[boost::_bi::storage1<boost::arg<I> >::a1_<1>]’ /usr/local/include/boost/bind/bind.hpp:243:60: note: candidates are: In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:170:27: note: template<class T> T& boost::_bi::list0::operator[](boost::_bi::value<T>&) const /usr/local/include/boost/bind/bind.hpp:170:27: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:243:60: note: mismatched types ‘boost::_bi::value<T>’ and ‘boost::arg<1>()’ In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:172:33: note: template<class T> const T& boost::_bi::list0::operator[](const boost::_bi::value<T>&) const /usr/local/include/boost/bind/bind.hpp:172:33: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:243:60: note: mismatched types ‘const boost::_bi::value<T>’ and ‘boost::arg<1>()’ In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:174:27: note: template<class T> T& boost::_bi::list0::operator[](const boost::reference_wrapper<T>&) const /usr/local/include/boost/bind/bind.hpp:174:27: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:243:60: note: mismatched types ‘const boost::reference_wrapper<T>’ and ‘boost::arg<1>()’ In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:176:76: note: template<class R, class F, class L> typename boost::_bi::result_traits<R, F>::type boost::_bi::list0::operator[](boost::_bi::bind_t<R, F, L>&) const /usr/local/include/boost/bind/bind.hpp:176:76: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind.hpp:22:0, from staticObject.cpp:2: /usr/local/include/boost/bind/bind.hpp:243:60: note: mismatched types ‘boost::_bi::bind_t<R, F, L>’ and ‘boost::arg<1>()’ /usr/local/include/boost/bind/bind.hpp:178:76: note: template<class R, class F, class L> typename boost::_bi::result_traits<R, F>::type boost::_bi::list0::operator[](const boost::_bi::bind_t<R, F, L>&) const /usr/local/include/boost/bind/bind.hpp:178:76: note: template argument deduction/substitution failed: /usr/local/include/boost/bind/bind.hpp:243:60: note: mismatched types ‘const boost::_bi::bind_t<R, F, L>’ and ‘boost::arg<1>()’ In file included from /usr/local/include/boost/bind/bind.hpp:29:0, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/bind/arg.hpp: In instantiation of ‘boost::arg<I>::arg(const T&) [with T = boost::arg<2>(); int I = 1]’: /usr/local/include/boost/bind/bind.hpp:313:9: required from ‘void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>; A = boost::_bi::list1<const std::basic_string<char>&>; A1 = boost::arg<1>; A2 = boost::arg<2>]’ /usr/local/include/boost/bind/bind_template.hpp:47:59: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(const A1&) [with A1 = std::basic_string<char>; R = void; F = boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>; L = boost::_bi::list2<boost::arg<1>, boost::arg<2> >; boost::_bi::bind_t<R, F, L>::result_type = void]’ /usr/local/include/boost/function/function_template.hpp:153:11: required from ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&]’ /usr/local/include/boost/function/function_template.hpp:934:60: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&]’ /usr/local/include/boost/function/function_template.hpp:722:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ /usr/local/include/boost/function/function_template.hpp:1069:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ staticObject.cpp:159:44: required from here /usr/local/include/boost/bind/arg.hpp:37:22: error: size of array is negative In file included from /usr/local/include/boost/bind/mem_fn.hpp:215:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/bind/mem_fn_template.hpp: In instantiation of ‘R boost::_mfi::mf1<R, T, A1>::call(U&, const void*, B1&) const [with U = const std::basic_string<char>; B1 = const std::basic_string<char>; R = void; T = BaseObject; A1 = const std::basic_string<char>&]’: /usr/local/include/boost/bind/mem_fn_template.hpp:179:42: required from ‘R boost::_mfi::mf1<R, T, A1>::operator()(const U&, A1) const [with U = std::basic_string<char>; R = void; T = BaseObject; A1 = const std::basic_string<char>&]’ /usr/local/include/boost/bind/bind.hpp:313:9: required from ‘void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>; A = boost::_bi::list1<const std::basic_string<char>&>; A1 = boost::arg<1>; A2 = boost::arg<2>]’ /usr/local/include/boost/bind/bind_template.hpp:47:59: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(const A1&) [with A1 = std::basic_string<char>; R = void; F = boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>; L = boost::_bi::list2<boost::arg<1>, boost::arg<2> >; boost::_bi::bind_t<R, F, L>::result_type = void]’ /usr/local/include/boost/function/function_template.hpp:153:11: required from ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&]’ /usr/local/include/boost/function/function_template.hpp:934:60: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&]’ /usr/local/include/boost/function/function_template.hpp:722:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ /usr/local/include/boost/function/function_template.hpp:1069:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf1<void, BaseObject, const std::basic_string<char>&>, boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; R = void; T0 = const std::basic_string<char>&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ staticObject.cpp:159:44: required from here /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: error: no matching function for call to ‘get_pointer(const std::basic_string<char>&)’ /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: note: candidates are: In file included from /usr/local/include/boost/bind/bind.hpp:25:0, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/ref.hpp:182:29: note: template<class T> T* boost::get_pointer(const boost::reference_wrapper<T>&) /usr/local/include/boost/ref.hpp:182:29: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind/mem_fn.hpp:215:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: note: ‘const std::basic_string<char>’ is not derived from ‘const boost::reference_wrapper<T>’ In file included from /usr/local/include/boost/bind/mem_fn.hpp:25:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/get_pointer.hpp:20:23: note: template<class T> T* boost::get_pointer(T*) /usr/local/include/boost/get_pointer.hpp:20:23: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind/mem_fn.hpp:215:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: note: mismatched types ‘T*’ and ‘std::basic_string<char>’ In file included from /usr/local/include/boost/bind/mem_fn.hpp:25:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/get_pointer.hpp:27:23: note: template<class T> T* boost::get_pointer(const std::auto_ptr<T>&) /usr/local/include/boost/get_pointer.hpp:27:23: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind/mem_fn.hpp:215:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: note: ‘const std::basic_string<char>’ is not derived from ‘const std::auto_ptr<T>’ In file included from /usr/local/include/boost/bind/mem_fn.hpp:25:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/get_pointer.hpp:34:23: note: template<class T> T* boost::get_pointer(const std::unique_ptr<T>&) /usr/local/include/boost/get_pointer.hpp:34:23: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind/mem_fn.hpp:215:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: note: ‘const std::basic_string<char>’ is not derived from ‘const std::unique_ptr<T>’ In file included from /usr/local/include/boost/bind/mem_fn.hpp:25:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/get_pointer.hpp:39:23: note: template<class T> T* boost::get_pointer(const std::shared_ptr<_Tp>&) /usr/local/include/boost/get_pointer.hpp:39:23: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/bind/mem_fn.hpp:215:0, from /usr/local/include/boost/mem_fn.hpp:22, from /usr/local/include/boost/bind/bind.hpp:26, from /usr/local/include/boost/bind.hpp:22, from staticObject.cpp:2: /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: note: ‘const std::basic_string<char>’ is not derived from ‘const std::shared_ptr<_Tp>’ /usr/local/include/boost/bind/mem_fn_template.hpp:156:53: error: return-statement with a value, in function returning 'void' [-fpermissive] make: *** [staticObject.o] Error 1 Thanks in advance, -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.
----------------------------------------
Date: Mon, 22 Apr 2013 00:52:27 -0600 From: tyler@tysdomain.com To: boost-users@lists.boost.org Subject: [Boost-users] boost::bind issues revisited
oHello all: I'm kind of at a loss here. It looks like ther'es an issue with boost::bind somewhere in the mess of 500 templates and 90 screens of errors and I don't know enough about the mess to untangle it. Any info would be awesome. First, the code:
sgroup->AddEntry(new OlcStringEntry("name", "Sets the name of the object", OF_NORMAL, boost::bind(&StaticObject::GetName, _1), <159> boost::bind(&StaticObject::SetName, _1, _2)));
the 159 I denoted is useful in the errors later. Now the rest of the code I'm using:
typedef boost::function<std::string ()> StringGetter; typedef boost::function<void (const std::string&)> StringSetter;
class IOlcEntry { protected: std::string _name; std::string _help; FLAG _flag; public: IOlcEntry(const std::string &name, const std::string &help, FLAG flag) { _flag = flag; _name = name; _help = help; } ~IOlcEntry() {} };
class OlcStringEntry:public IOlcEntry { protected: StringGetter _getter; StringSetter _setter; public: OlcStringEntry(const std::string &name, const std::string &help, FLAG flag, const StringGetter getter, const StringSetter setter) :IOlcEntry(name, help, flag) { _setter = setter; _getter = getter; } };
Looks like you are trying to pass "boost::bind(&StaticObject::GetName, _1)", which is a 1-argument function object, as the argument for a parameter of type "StringGetter", which is a typedef for "boost::function<std::string ()>", which is a 0-argument function object. You have a similar problem for the setter. Perhaps you meant to bind the getter and setter to a specific instance of StaticObject? In that case, assuming 'my_instance' is that instance, you should write: boost::bind(&StaticObject::GetName, my_instance) and boost::bind(&StaticObject::SetName, my_instance, _1) and then you'll have function objects that are assignable to StringGetter and StringSetter, respectively. Regards, Nate
On 4/22/2013 1:07 AM, Nathan Ridge wrote:
----------------------------------------
Date: Mon, 22 Apr 2013 00:52:27 -0600 From: tyler@tysdomain.com To: boost-users@lists.boost.org Subject: [Boost-users] boost::bind issues revisited
Hello all: I'm kind of at a loss here. It looks like ther'es an issue with boost::bind somewhere in the mess of 500 templates and 90 screens of errors and I don't know enough about the mess to untangle it. Any info would be awesome. First, the code:
sgroup->AddEntry(new OlcStringEntry("name", "Sets the name of the object", OF_NORMAL, boost::bind(&StaticObject::GetName, _1), <159> boost::bind(&StaticObject::SetName, _1, _2)));
the 159 I denoted is useful in the errors later. Now the rest of the code I'm using:
typedef boost::function<std::string ()> StringGetter; typedef boost::function<void (const std::string&)> StringSetter;
class IOlcEntry { protected: std::string _name; std::string _help; FLAG _flag; public: IOlcEntry(const std::string &name, const std::string &help, FLAG flag) { _flag = flag; _name = name; _help = help; } ~IOlcEntry() {} };
class OlcStringEntry:public IOlcEntry { protected: StringGetter _getter; StringSetter _setter; public: OlcStringEntry(const std::string &name, const std::string &help, FLAG flag, const StringGetter getter, const StringSetter setter) :IOlcEntry(name, help, flag) { _setter = setter; _getter = getter; } }; Looks like you are trying to pass "boost::bind(&StaticObject::GetName, _1)", which is a 1-argument function object, as the argument for a parameter of type "StringGetter", which is a typedef for "boost::function<std::string ()>", which is a 0-argument function object.
You have a similar problem for the setter.
Perhaps you meant to bind the getter and setter to a specific instance of StaticObject? In that case, assuming 'my_instance' is that instance, you should write:
boost::bind(&StaticObject::GetName, my_instance)
and
boost::bind(&StaticObject::SetName, my_instance, _1)
and then you'll have function objects that are assignable to StringGetter and StringSetter, respectively.
Regards, Nate
Hello: I should have been more clear in my original message. Basically what I'm doing is creating a method that I can use to edit objects in game. Rather than attach this to every object, the idea was to set up a collection of editor entries. When I wanted to edit an object I can call these entries on the object. This saves a lot of overhead because rather than there being x*n (where n is the amount of objects) entries, there's just x and each object can call into them when it is edited. I was trying to use _1 etc as placeholders for the "this" pointer; is it possible to do that? I'd like to be able to use any StaticObject I wish with these entries, but I need a way to pass in the this pointer for the object. Thanks,
On 4/22/2013 10:29 AM, Littlefield, Tyler wrote:
On 4/22/2013 1:07 AM, Nathan Ridge wrote:
----------------------------------------
Date: Mon, 22 Apr 2013 00:52:27 -0600 From: tyler@tysdomain.com To: boost-users@lists.boost.org Subject: [Boost-users] boost::bind issues revisited
Hello all: I'm kind of at a loss here. It looks like ther'es an issue with boost::bind somewhere in the mess of 500 templates and 90 screens of errors and I don't know enough about the mess to untangle it. Any info would be awesome. First, the code:
sgroup->AddEntry(new OlcStringEntry("name", "Sets the name of the object", OF_NORMAL, boost::bind(&StaticObject::GetName, _1), <159> boost::bind(&StaticObject::SetName, _1, _2)));
the 159 I denoted is useful in the errors later. Now the rest of the code I'm using:
typedef boost::function<std::string ()> StringGetter; typedef boost::function<void (const std::string&)> StringSetter;
class IOlcEntry { protected: std::string _name; std::string _help; FLAG _flag; public: IOlcEntry(const std::string &name, const std::string &help, FLAG flag) { _flag = flag; _name = name; _help = help; } ~IOlcEntry() {} };
class OlcStringEntry:public IOlcEntry { protected: StringGetter _getter; StringSetter _setter; public: OlcStringEntry(const std::string &name, const std::string &help, FLAG flag, const StringGetter getter, const StringSetter setter) :IOlcEntry(name, help, flag) { _setter = setter; _getter = getter; } }; Looks like you are trying to pass "boost::bind(&StaticObject::GetName, _1)", which is a 1-argument function object, as the argument for a parameter of type "StringGetter", which is a typedef for "boost::function<std::string ()>", which is a 0-argument function object.
You have a similar problem for the setter.
Perhaps you meant to bind the getter and setter to a specific instance of StaticObject? In that case, assuming 'my_instance' is that instance, you should write:
boost::bind(&StaticObject::GetName, my_instance)
and
boost::bind(&StaticObject::SetName, my_instance, _1)
and then you'll have function objects that are assignable to StringGetter and StringSetter, respectively.
Regards, Nate
Hello: I should have been more clear in my original message. Basically what I'm doing is creating a method that I can use to edit objects in game. Rather than attach this to every object, the idea was to set up a collection of editor entries. When I wanted to edit an object I can call these entries on the object. This saves a lot of overhead because rather than there being x*n (where n is the amount of objects) entries, there's just x and each object can call into them when it is edited. I was trying to use _1 etc as placeholders for the "this" pointer; is it possible to do that? I'd like to be able to use any StaticObject I wish with these entries, but I need a way to pass in the this pointer for the object. Thanks,
Then: boost::bind(&StaticObject::GetName, _1) and boost::bind(&StaticObject::SetName, _1, _2) would work for you? Jeff
On 4/22/2013 2:13 PM, Jeff Flinn wrote:
On 4/22/2013 10:29 AM, Littlefield, Tyler wrote:
On 4/22/2013 1:07 AM, Nathan Ridge wrote:
Date: Mon, 22 Apr 2013 00:52:27 -0600 From: tyler@tysdomain.com To: boost-users@lists.boost.org Subject: [Boost-users] boost::bind issues revisited
Hello all: I'm kind of at a loss here. It looks like ther'es an issue with boost::bind somewhere in the mess of 500 templates and 90 screens of errors and I don't know enough about the mess to untangle it. Any info would be awesome. First, the code:
sgroup->AddEntry(new OlcStringEntry("name", "Sets the name of the object", OF_NORMAL, boost::bind(&StaticObject::GetName, _1), <159> boost::bind(&StaticObject::SetName, _1, _2)));
the 159 I denoted is useful in the errors later. Now the rest of the code I'm using:
typedef boost::function<std::string ()> StringGetter; typedef boost::function<void (const std::string&)> StringSetter;
class IOlcEntry { protected: std::string _name; std::string _help; FLAG _flag; public: IOlcEntry(const std::string &name, const std::string &help, FLAG flag) { _flag = flag; _name = name; _help = help; } ~IOlcEntry() {} };
class OlcStringEntry:public IOlcEntry { protected: StringGetter _getter; StringSetter _setter; public: OlcStringEntry(const std::string &name, const std::string &help, FLAG flag, const StringGetter getter, const StringSetter setter) :IOlcEntry(name, help, flag) { _setter = setter; _getter = getter; } }; Looks like you are trying to pass "boost::bind(&StaticObject::GetName, _1)", which is a 1-argument function object, as the argument for a
---------------------------------------- parameter of type "StringGetter", which is a typedef for "boost::function<std::string ()>", which is a 0-argument function object.
You have a similar problem for the setter.
Perhaps you meant to bind the getter and setter to a specific instance of StaticObject? In that case, assuming 'my_instance' is that instance, you should write:
boost::bind(&StaticObject::GetName, my_instance)
and
boost::bind(&StaticObject::SetName, my_instance, _1)
and then you'll have function objects that are assignable to StringGetter and StringSetter, respectively.
Regards, Nate
Hello: I should have been more clear in my original message. Basically what I'm doing is creating a method that I can use to edit objects in game. Rather than attach this to every object, the idea was to set up a collection of editor entries. When I wanted to edit an object I can call these entries on the object. This saves a lot of overhead because rather than there being x*n (where n is the amount of objects) entries, there's just x and each object can call into them when it is edited. I was trying to use _1 etc as placeholders for the "this" pointer; is it possible to do that? I'd like to be able to use any StaticObject I wish with these entries, but I need a way to pass in the this pointer for the object. Thanks,
Then:
(forgot the update typedefs) typedef boost::function<std::string (const some_base_type*)> StringGetter; typedef boost::function<void (some_base_type*, const std::string&)> StringSetter;
boost::bind(&StaticObject::GetName, _1)
and
boost::bind(&StaticObject::SetName, _1, _2)
would work for you?
Jeff
participants (3)
-
Jeff Flinn
-
Littlefield, Tyler
-
Nathan Ridge