
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*

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

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?

________________________________________ From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Dailey Sent: Friday, February 06, 2009 8:57 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [ptr_container] ptr_map and cloning issues
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" ); }
At first you said "...this compiles without any problems for me" and then you said "...the uncommented does not compile...". So which is it?
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. John

On Fri, Feb 6, 2009 at 9:03 AM, John Wilkinson <jwilkinson@tsystem.com>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.

On Fri, Feb 6, 2009 at 9:55 AM, Robert Dailey <rcdailey@gmail.com> wrote:
On Fri, Feb 6, 2009 at 9:03 AM, John Wilkinson <jwilkinson@tsystem.com>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...

Try commenting out the textures.find line - I think that you will still get the error. It's the returned pointer that is the problem. John ________________________________ From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Dailey Sent: Friday, February 06, 2009 10:06 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [ptr_container] ptr_map and cloning issues On Fri, Feb 6, 2009 at 9:55 AM, Robert Dailey <rcdailey@gmail.com> wrote: On Fri, Feb 6, 2009 at 9:03 AM, John Wilkinson <jwilkinson@tsystem.com> 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...

On Fri, Feb 6, 2009 at 10:06 AM, Robert Dailey <rcdailey@gmail.com> wrote:
On Fri, Feb 6, 2009 at 9:55 AM, Robert Dailey <rcdailey@gmail.com> wrote:
On Fri, Feb 6, 2009 at 9:03 AM, John Wilkinson <jwilkinson@tsystem.com>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.
participants (3)
-
John Wilkinson
-
Robert Dailey
-
Thorsten Ottosen