Boost logo

Boost Users :

Subject: Re: [Boost-users] [ptr_container] ptr_map and cloning issues
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-02-06 07:30:14


Robert Dailey skrev:
> I have a ptr_map as follows:
>
> typedef boost::ptr_map<std::string, Texture> TextureContainer;
>
> I only use forward declarations of Texture where needed. When I'm
> iterating over an instance of TextureContainer, I expect to not have to
> do more than use the forward declaration since technically we're only
> iterating pointer values and the definition of Texture is not needed for
> this. So when I do this:
>
> TextureContainer myTextures;
> TextureContainer::const_iterator it = myTextures.find( "some key" );
>
> The above (second line) results in an extremely complex and long
> compiler error, but the important part of the error says what I have
> pasted below. Why is this error happening? Is it trying to clone Texture
> objects? This shouldn't be happening.
>
> /boost/ptr_container/clone_allocator.hpp(34) : error C2514:
> 'rs::Texture' : class has no constructors
> C:\IT\work\planb\components\rs/renderer/TextureFwd.hpp(6) : see
> declaration of 'rs::Texture'
>
> C:\IT\work\planb\third_party\boost\1_37_0\boost/ptr_container/clone_allocator.hpp(55)
> : see reference to function template instantiation 'T
> *boost::new_clone<U>(const T &)' being compiled/

Hm. I can't really recreate this with vc9. What compiler are you using?

First, this compiles without any problems for me:

     class Texture;
     typedef boost::ptr_map<std::string,Texture> MapType;

     void foo( const MapType& m )
     {
         //MapType map;
         MapType::const_iterator i = m.find( "foo" );
         //i = map.find( "foo" );
     }

Now, the uncommented does not compile because the destructor may need to
delete objects of type Texture, and boost::check_delete() refuses to do
that on incomplete types.

-Thorsten


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