// in Utility.h define this
SDL_Surface GetImage(std::string imageName);
// in Utility.cpp, do this
std::map<std::string, SDL_Surface*> ImageMap;
SDL_Surface *GetImage(std::string imageName)
{
// check if this image is in the map
if (ImageMap.find(imageName) == std::map::end) {
// load it once into the map
ImageMap[imageName] = IMG_Load(imageName);
}
return ImageMap[imageName];
}
// Then, when you want to load an image, #include "Utility.h" and call
SDL_Surface *PlayerImage = GetImage("player.png");
You can put Utility into a Utility namespace if you want, but that's just another option.Good Luck.