Hi guys,
I've been spoilt with c# coding the last few years and now I'm back onto c++ and finding that I'm having trouble with stuff that is supposed to be simple.
Heres my code:
System.h
#pragma once
#include <string>
#include <map>
#include "DarkGDK.h"
using namespace std;
class System
{
public:
System();
~System();
void Initialize();
static void LoadImage(string fileName, string id);
static int GetImage(string id);
private:
map<string, int> m_images;
};
System.cpp
#include "System.h"
System::System()
{
}
System::~System()
{
}
void System::Initialize()
{
dbSetDisplayMode (1024, 640, 32);
dbSetWindowTitle ("the Laboratory");
dbSetWindowPosition(100, 10);
dbSyncOn ();
dbSyncRate (60);
dbRandomize(dbTimer());
}
void System::LoadImage(string fileName, string id)
{
int i = 1;
while (dbImageExist(i))
{
i++;
}
dbLoadImage(const_cast<char*>(fileName.c_str()), i, 1);
m_images[id] = i;
}
int System::GetImage(string id)
{
return m_images[id];
}
The idea here is to have a map which maps strings against integer values, to access images with a string instead of hardcoded values. This class isn't done, so it doesn't handle anything like unloading images. I want to access the image methods without passing an instance of System, so I used static.
Now i get this error:
blahblah\system.cpp(39) : error C2677: binary '[' : no global operator found which takes type 'std::string' (or there is no acceptable conversion)
If I change the map to static, I get this linker error:
1>System.obj : error LNK2001: unresolved external symbol "private: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,int> > > System::m_images" (?m_images@System@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HU?$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@@H@std@@@2@@std@@A)
Can any of you bright chaps help me out?
cheers,
Draknir