I am getting the following linker error:
Error 1 error LNK2001: unresolved external symbol “private: static class std::map,class std::allocator >,struct SDL_Surface *,struct std::less,class std::allocator > >,class std::allocator,class std::allocator > const ,struct SDL_Surface *> > > CSurface::loadedSurfaces” (?loadedSurfaces@CSurface@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAUSDL_Surface@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAUSDL_Surface@@@std@@@2@@std@@A) CSurface.obj
The code for the header and cpp file for the CSurface compilation unit is at:
What is causing this linker error to happen 🙁 its driving me mad.
You have declared
loadedSurfacesbut you have not defined it. You need to add the following to exactly one translation unit to actually declare the variable:As it is now, the
loadedSurfacesinside the class definition is like the prototype of the function. When you try to use it, the linker goes and looks for it because it sees the forward declaration, but it never finds the actual definition anywhere. You have to give it a definition and the linker will be satisfied because it knows what actual variable in what actual translation unit everyone is talking about when they use the nameloadedSurfaces.