Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind issues revisited
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2013-04-22 03:07:34


---------------------------------------- > Date: Mon, 22 Apr 2013 00:52:27 -0600 > From: tyler_at_[hidden] > To: boost-users_at_[hidden] > 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net