Re: STL Map Scoping Issue
<sfncook@gmail.com> wrote in message...
Just a couple of *suggestions*....
( I think Frank nailed your problem.)
********* typedefs.h *****************
#include "stdlib.h"
Is "stdlib.h" a file you wrote? If you intended the standard stdlib, you
should use:
#include <stdlib.h>
.... or the C++ version:
#include <cstdlib> // you may need to add 'std::' to the 'calls'.
#include <map>
#include <vector>
Remove that <vector> header if you are not using it.
typedef struct _ShipType {
An underline followed by an uppercase letter is reserved to implementation.
I'd use something else there ( like Ship_Type).
int a;
int b;
int c;
} ShipType;
Why not just:
struct ShipType{
int a;
int b;
int c;
};
[snip]
#include "typedefs.h"
class GameLoader{
private:
Ok if you need the documentation, but, 'class' defaults to 'private', so,
it's not required.
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;
}
If you add a constructor to your struct:
struct ShipType{
int a;
int b;
int c;
ShipType( int aa, int bb, int cc) : a(aa), b(bb), c(cc){}
// ShipType() : a(0), b(0), c(0){} // might also want this
}; // note: no longer a POD type
.... then you could do:
void GameLoader::LoadGame(){
shipTypeMap[0] = new ShipType( 1, 2, 3 );
}
****************** MainFile.cpp *********************
#include "GameLoader.h"
#include <stdlib.h>
#include <iostream>
#include <map>
int main(int argc, char* argv[])
If you are not using the command line args:
int main()
{
printf("Callback function test.\n");
GameLoader * gl = new GameLoader();
gl->LoadGame();
std::cout<<shipTypeMap[0]->a<<std::endl;
delete shipTypeMap[0];
getchar();
return 0;
}
--
Bob R
POVrookie