Unresoled symbol linker error

This is a discussion on Unresoled symbol linker error within the C++ Programming forums, part of the General Programming Boards category; Hopefully the last major question on this project... I know what this error typically means - that the linker couldn't ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    56

    Unresoled symbol linker error

    Hopefully the last major question on this project...

    I know what this error typically means - that the linker couldn't find the function definition that you used and declared. But I'm confused. I have two cpp files (driver and MemoryManager) and a header file (MemoryManager). part of driver.cpp's main():

    Code:
    // previously defined simple class called MyTest
    MemoryManager::Mgr mem( MemoryManager::printall );
    MyTest* foo = mem.alloc<MyTest>();
    Now in the header file:
    Code:
    class Mgr {
    
    public:
    	// some snippage, I think these are the relevant parts
    	template< class T > T* alloc( int = 1 );
    protected:
    	pvomap allPtrs;
    
    };
    And in the definition file:
    Code:
    	template<class T> T* Mgr::alloc( int a ) {
    
    		T* ptr = new T[a];
    		allPtrs[ ptr ] += a;
    		return ptr;
    
    	}
    This function gets called and appears to me to be defined. Using Borland 5.5.1, I run:
    bcc32 driver.cpp MemoryManager.cpp
    It compiles correctly but generates the linker error:
    Unresolved external 'MyTest * MemoryManager::Mgr::alloc<MyTest>(int)' referenced from DRIVER.OBJ. I cannot figure out why I'm getting this - the compiler doesn't complain that I've left a member function undefined or that I've defined one that doesn't exist, and as near as I can tell the prototypes match. Can anybody see why it will not work? TIA!

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Are you sure that MemoryManager.cpp is including MemoryManager.h?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    56
    Indeed, it is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 02:17 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 01:17 AM
  3. Can't resolve linker error!!!!
    By benshums in forum C++ Programming
    Replies: 3
    Last Post: 01-01-2008, 02:48 PM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM

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