Boost logo

Boost Users :

Subject: Re: [Boost-users] [ptr_container] ptr_map and cloning issues
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2009-02-06 11:13:03


On Fri, Feb 6, 2009 at 10:06 AM, Robert Dailey <rcdailey_at_[hidden]> wrote:

> On Fri, Feb 6, 2009 at 9:55 AM, Robert Dailey <rcdailey_at_[hidden]> wrote:
>
>> On Fri, Feb 6, 2009 at 9:03 AM, John Wilkinson <jwilkinson_at_[hidden]>wrote:
>>
>>> It's the commented-out code that will not compile. When the instance of
>>> MapType goes out of scope, the type of the contained pointers cannot be
>>> unknown, because they have to be deleted.
>>
>>
>> My specific issue isn't about scope, it's strictly usage of a reference. I
>> know for a fact that the container is not being destroyed at this specific
>> area of code. Below is what I'm actually doing:
>>
>> static Texture const* FindTexture( std::string const& textureId,
>> TextureContainer const& textures )
>> {
>> TextureContainer::const_iterator it = textures.find( textureId );
>> if( it == textures.end() )
>> {
>> /// @todo Throw an exception here?
>> assert(0);
>> }
>>
>> return it->second;
>> }
>>
>> And since the error message is so long I've placed that in a text file and
>> attached that to this email. If there's anything else I can provide I'd be
>> happy to. I have no leads on what this error could mean. I wish it wasn't so
>> cryptic.
>>
>
> When I provide the full class definition (versus the forward declaration),
> it still fails because class Texture is boost::noncopyable. Why is
> ptr_map::find() trying to copy construct a Texture? This shouldn't be
> happening...
>

After much trial & error, I found the problem. It was the way I was invoking
FindTexture():

        std::for_each(
            definition.frames.begin(),
            definition.frames.end(),
            bind( &Animation::AddFrame, *animation, bind( &FindTexture, _1,
textures ) )
            );

I'm passing in "textures" to FindTexture by-value, I needed to use
boost::ref(). So now it looks like:

        std::for_each(
            definition.frames.begin(),
            definition.frames.end(),
            bind( &Animation::AddFrame, *animation, bind( &FindTexture, _1,
boost::ref( textures ) ) )
            );

The compiler error wasn't helpful at all so I just had to keep commenting
out things until it lead me to the real problem. Thanks for the help guys.



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