Re: STL Map Scoping Issue
Wow! You guys are great! Thanks for the responses so far. However, I
forgot to mention one factor that must make the difference: The code
is broken up into different files. I copied the code you had and ran
it fine from a single file as well. However when I divide the code
into different files (as is below) then I get the AV. Thanks a
million for the help so far. Please teach me oh wise sages.
********* typedefs.h *****************
#include "stdlib.h"
#include <map>
#include <vector>
typedef struct _ShipType {
int a;
int b;
int c;
} ShipType;
static std::map<int, ShipType *> shipTypeMap;
************** GameLoader.h ********************
#pragma warning (disable : 4786) //This is a fix for a Microsoft
acknowledged bug.
#include "typedefs.h"
class GameLoader
{
private:
public:
GameLoader(){};
virtual ~GameLoader(){};
void LoadGame();
};
************ GameLoader.cpp *********************
#include "GameLoader.h"
void GameLoader::LoadGame()
{
shipTypeMap[0] = new ShipType();
shipTypeMap[0]->a = 1;
shipTypeMap[0]->b = 2;
shipTypeMap[0]->c = 3;
}
****************** MainFile.cpp *********************
#include "GameLoader.h"
#include <stdlib.h>
#include <iostream>
#include <map>
int main(int argc, char* argv[])
{
printf("Callback function test.\n");
GameLoader * gl = new GameLoader();
gl->LoadGame();
std::cout<<shipTypeMap[0]->a<<std::endl;
delete shipTypeMap[0];
getchar();
return 0;
}
^^^^^^^^^ FIN ^^^^^^^^^^^^^^^