Template problem with boost::shared_ptr

Started by
1 comment, last by sipickles 17 years, 1 month ago
Add function:

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



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

This topic is closed to new replies.

Advertisement