Jump to content
  • Advertisement
Sign in to follow this  
sipickles

Template problem with boost::shared_ptr

This topic is 4162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Add function:


boost::shared_ptr<cTexture> tempTexture = g_simulation->GetTextureManager()->Add( texName, path );





template:

template< class Type > class ResourceManager


Share this post


Link to post
Share on other sites
Advertisement
Hello, I'm trying to update my resourceManager to use boost::shared_ptrs, but have hit a hole in my knowledge! When I normally allocate a shared_ptr elsewhere, I do so like this: boost::shared_ptr<CMyObject> obj(new CMyObject); using a default constructor. works fine. In my resource manager, which is a template, I get confused. Here's what I am trying:

	boost::shared_ptr<Type> Add( std::string name, std::string path = "" )
	{
		// If the element already exists, then return a pointer to it.
		boost::shared_ptr<Type> element = GetElement( name );
		if( element != NULL )
		{
			g_log->SIM( "Resource already in use: %s\n", const_cast<char*>(name.c_str()) );
			return element;
		}

		// Create the resource
		boost::shared_ptr<Type> resource(new Type( name, path ));
		g_log->SIM( "New resource required: %s\n", const_cast<char*>(name.c_str()) );

		// Add the new resource to the manager and return a pointer to it.
		return *(m_list->Add( &resource ));
}

The type is a cTexture whose constructor looks like this: cTexture( std::string name, std::string path = "data\\shaders\\" ); The compiler complains on the line: boost::shared_ptr<Type> resource(new Type( name, path )); Saying:
error C2661: 'boost::shared_ptr<T>::shared_ptr' : no overloaded function takes 2 arguments
        with
        [
            T=cTexture
        ]
while compiling class template member function 'boost::shared_ptr<T> ResourceManager<Type>::Add(std::string,std::string)'
        with
        [
            T=boost::shared_ptr<cTexture>,
            Type=boost::shared_ptr<cTexture>
        ]



I don't understand why the template type is shared_ptr<cTexture>, not cTexture. Why can't it see the cTexture constructor? Thanks in advance. Si

Share this post


Link to post
Share on other sites
Where is the call to the Add() function which causes this error? What is the type parameter of the manager that you instantiated?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!