Weird <template> syntax error

This is a discussion on Weird <template> syntax error within the C++ Programming forums, part of the General Programming Boards category; I'll just post the code, Apparently I'm performing some kind of illegal overload Resource_Manager.h Code: template < typename resource_t > ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Weird <template> syntax error

    I'll just post the code, Apparently I'm performing some kind of illegal overload

    Resource_Manager.h
    Code:
    template < typename resource_t >
    class Manager
    {
    
        std::map< std::string , resource_t* > Resources;
    
    public:
    
        resource_t & Load( const std::string & filename );
    
    
    	virtual ~Manager( void )
    	{
    		std::map< std::string ,  resource_t * >::iterator destroyer, end;
    		for ( destroyer = Resources.begin() , end = Resources.end() ; destroyer != end ; ++destroyer ) 
    		{
    			delete destroyer->second;
    		}
    	}	
    
    };
    Resource_Manager.cpp
    Code:
    template < typename resource_t >
    resource_t & Manager<resource_t>::Load( std::string & filename ) 
    {
    	std::map< std::string , resource_t* >::iterator entry = Resources.find( filename );
        if ( entry != resources.end() ) // if the entry is found
    	{ 
    		return * entry->second; // return the reference to the resource
        } 
    	else
    	{
    		resource_t* resource( new resource_t( filename ) );
    		
    		// first we gotta load the resource, then we can make a pair
    		// and return the reference
    	
    		resources.insert( std::make_pair( filename , resource ) );
    		return * resource;
        }
    }
    And of course this bugger of an error
    Code:
    C:\Documents and Settings\Jonathan\My Documents\C++ Programming\Resource_Manager\Resource_Manager.cpp(48) : error C2244: 'Manager<resource_t>::Load' : unable to resolve function overload
    I'm sure it is a silly syntax error I can't spot, any takers?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Code:
    // header
    resource_t & Load( const std::string & filename ); // const filename
    
    // cpp
    resource_t & Manager<resource_t>::Load( std::string & filename ) // non const filename
    Also (I'm sure you know this, but thought I'd mention it anyway) you can't really put template function definitions in .cpp files (unless you're lucky enough to have a compiler that supports the export keyword).
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Doh, that was it...

    And yeah, Imagine that, VC 6 pulls through!
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  2. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21