This question already has an answer here:
- Initializing private static members 11 answers
At the moment I'm programming a 2D game framework with SDL and I have a problem with my sprite handler. I need a static map for my loaded textures.
SpriteHandler.cpp
:
#include "SpriteHandler.h"
SpriteHandler::SpriteHandler(SDL_Renderer* rendere)
{
renderer = rendere;
console = new ConsoleHandler("SpriteHandler");
console->printInfo("Initialisation ..");
}
bool SpriteHandler::RegisterTexture(int uuid, std::string file){
std::string path = "./assets/textures/" + file;
if (textures.count(uuid)){
console->printWarning("UUID " + std::to_string(uuid) + " already registered! Skipping ..");
return false;
}
if (!FileExists(path)){
console->printWarning("Texture '" + file + "' cannot be found. Skipping ..");
return false;
}
SDL_Texture* sprite = SDL_CreateTextureFromSurface(renderer, IMG_Load(path.c_str()));
textures[uuid] = sprite;
console->printInfo("Loaded " + file);
return true;
}
bool SpriteHandler::FileExists(std::string StrFilename){
GetFileAttributes(StrFilename.c_str());
if (0xffffffff == GetFileAttributes(StrFilename.c_str()))
return false;
return true;
}
SpriteHandler::~SpriteHandler()
{
}
SpriteHandler.h
:
#include <map>
#include <SDL.h>
#include <SDL_image.h>
#include <string>
#include <Windows.h>
#include "ConsoleHandler.h"
#pragma once
class SpriteHandler
{
private:
static std::map<int, SDL_Texture*> textures; //Here the error occurs
ConsoleHandler* console;
SDL_Renderer* renderer;
bool FileExists(std::string StrFilename);
public:
SpriteHandler(SDL_Renderer* rendere);
bool RegisterTexture(int uuid, std::string file);
~SpriteHandler();
};
Nothing special but I get a compiler error when I try to compile:
SpriteHandler.obj : error LNK2001: unresolved external symbol "private: static class std::map<int,struct SDL_Texture *,struct std::less<int>,class std::allocator<struct std::pair<int const ,struct SDL_Texture *> > > SpriteHandler::textures" (?textures@SpriteHandler@@0V?$map@HPAUSDL_Texture@@U?$less@H@std@@V?$allocator@U?$pair@$$CBHPAUSDL_Texture@@@std@@@3@@std@@A)
BTW: Sorry for bad English.
Aucun commentaire:
Enregistrer un commentaire