I''m having a bit of trouble here with std::map and I hope someone can give me an explanation. To sum up the problem, I''m storing pointers in a map and using a char* name as the reference to them. I can use text incapsulated in quotes as the first parameter and I''m able to retrieve the pointer just fine, but I cannot use a char* variable with the name stored in it. Let me post some code for clarification:
std::map<char*, mFileSystemInterface*> filesystems;
//this works:
this->filesystems.insert(std::make_pair((char*)"zip", zipfilesystem));
//this does not work:
char* MyName = "zip"
this->filesystems.insert(std::make_pair(MyName, zipfilesystem));
Here is my pointer retrieving code:
std::map<char*, mFileSystemInterface*>::iterator it;
it = filesystems.find(fsname);
if (it == filesystems.end())
{
//It couldn''t find the pointer
mLog::l->Write("%s didn''t work", fsname);
it = filesystems.find("stdio");
return it->second;
}
else
{
//It found the pointer
mLog::l->Write("%s worked", fsname);
return it->second;
}
For some odd reason I can retrieve the pointer if I added the name via (char*)"zip", but if I add it with MyName it just refuses to work. Does anyone know why this is?
MindEngine Development
http://medev.sourceforge.net