Skip to main content
gamedev.net
🔒 Locked

Template problem with boost::shared_ptr

Started by sipickles Mar 26, 2007 at 12:13 PM 1 replies 1k views
Original Post
sipickles
sipickles
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 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 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, not cTexture. Why can't it see the cTexture constructor? Thanks in advance. Si
sipickles
sipickles
Add function:

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



template:
template< class Type > class ResourceManager
ToohrVyk
ToohrVyk
Where is the call to the Add() function which causes this error? What is the type parameter of the manager that you instantiated?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.