STL map problem

Started by
9 comments, last by steeg 18 years ago
Hello, I'm a newbie using STL, and have been trying to setup a map for resource management within my game, but keep getting a linkage problem. Here is the code for the header file:

#ifndef RESMANAGER_H
#define RESMANAGER_H
#include <map>
#include <string>
#include "SDL.h"

class CResManager {
public:
	static CResManager* get() {
		return &instance;
	}
protected:
	CResManager(void);
	virtual ~CResManager(void);
private:
	static CResManager instance;
	std::map<std::string, SDL_Surface*> images;
};
#endif

I thought it had something to do with the fact that I was storing pointers, but even a simpl std::map<std:string, std:string> gives an error. Any help is appreciated. Thanks.
Advertisement
What is the exact linker error?


jfl.
I bet the linker is complaining about the static instance; "unresolved external" or some such.

steeg, your static CResManager instance; is only a declaration, you still need to add CResManager CResManager::instance; to some CPP file to define the variable.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Fruny
I bet the linker is complaining about the static instance; "unresolved external" or some such.

steeg, your static CResManager instance; is only a declaration, you still need to add CResManager CResManager::instance; to some CPP file to define the variable.


yes, I have that on my .cpp file, which is just blank right now:
#include "ResManager.h"CResManager CResManager::instance;CResManager::CResManager(void) {}CResManager::~CResManager(void) {}


and the error I am getting (say when I use std::map<std:string, std:string> is:

ResManager.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: bool __thiscall std::_Tree (and it goes on for lines and lines...)
Quote:Original post by steeg
and the error I am getting (say when I use std::map<std:string, std:string> is:

ResManager.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: bool __thiscall std::_Tree (and it goes on for lines and lines...)


This is a build settings issue. Creating a new project and copying your source files into it should fix it.

A quick [google] turns up people who have had the same problem (and had other less drastic possible solutions, if you have a bunch of custom build settings you'd rather not trash)
Or you can make sure that "Ignore All Default Libraries" is set to No (Project->Properties->Configuration Properties->Linker->Input).


jfl.
thanks for the replies...I'll try out the solution given in the other thread.
you can try gdb and do a stack trace.
Quote:Original post by Tradone
you can try gdb and do a stack trace.


He is having linker errors, not runtime errors.
Original post by steeg
Quote:Original post by Fruny
and the error I am getting (say when I use std::map<std:string, std:string> is:

ResManager.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: bool __thiscall std::_Tree (and it goes on for lines and lines...)
Ah. You aren't using VS2005 Express by chance, are you?
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement