Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind issues revisited
From: Jeff Flinn (Jeffrey.Flinn_at_[hidden])
Date: 2013-04-22 14:13:26


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_at_[hidden]
>>> To: boost-users_at_[hidden]
>>> 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


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