tmp/map.o: In function `Map::unloadMap(Map*)': map.cpp:(.text+0x6e): undefined reference to `Map::maps' map.cpp:(.text+0xa9): undefined reference to `Map::maps' tmp/map.o: In function `Map::getMap(QString)': map.cpp:(.text+0x10b): undefined reference to `Map::maps' map.cpp:(.text+0x136): undefined reference to `Map::maps' map.cpp:(.text+0x146): undefined reference to `Map::maps' tmp/map.o:map.cpp:(.text+0x167): more undefined references to `Map::maps' follow collect2: ld returned 1 exit status //----------------------------------------------------------------------- //----------------------------------------------------------------------- // map.h #ifndef MAP_H #define MAP_H #include #include class Map { public: static Map *getMap(QString name); static void unloadMap(QString name); static void unloadMap(Map *map); void used() { gamesUsing++; }; void notUsed() { gamesUsing--; if(!gamesUsing) unloadMap(this); }; protected: static QMap maps; Map(QString name); const QString name; unsigned short gamesUsing; }; #endif //----------------------------------------------------------------------- //----------------------------------------------------------------------- // map.cpp #include "map.h" Map::Map(QString name) : name(name), gamesUsing(0) { } Map *Map::getMap(QString name) { if(maps.contains(name)) return maps[name]; // TODO: What if the map file doesn't exist? Need to return 0 if that happens maps[name] = new Map(name); } void Map::unloadMap(QString name) { if(!maps.contains(name)) return; if(maps[name]->gamesUsing) return; // Don't unload if a game is using it delete maps[name]; maps.remove(name); } void Map::unloadMap(Map *map) { if(map->gamesUsing) return; // Don't unload if a game is using it QString name = maps.key(map); delete map; maps.remove(name); }