On Fri, Feb 6, 2009 at 6:30 AM, Thorsten Ottosen <thorsten.ottosen@dezide.com> wrote:
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.

I'm using VC9 as well. If the find() and iterator assignment do not compile for you then you are probably experiencing the same problem I am. Could you explain why the type must be known at this point? If I were to use a std::map<std::string, Texture*> I doubt I would have this problem. I was expecting the same of ptr_map.

At first you said "...this compiles without any problems for me" and then you said "...the uncommented does not compile...". So which is it?