Hi, I'm very new to c++ and c, and i'm attempting to make an image manager, preferably something that has static functions to retrieve the objects saved in it from any class...
(ie, you can call ImageManager::loadAsset() from the main function, and also ImageManager::getImage() from a sprite class to load the image instance...)
I understand that to make a "Static Class" you can place the constructor as private, but I'm having trouble retrieving the sf::Image to get an instance of the image loaded... here is a very simple example i'm trying.
#include <SFML/Graphics.hpp>
class ImageManager {
public:
static const sf::Image& getImage();
protected:
private:
ImageManager();
virtual ~ImageManager();
static sf::Image image;
};
and
#include "ImageManager.h"
ImageManager::ImageManager() {
}
ImageManager::~ImageManager() {
}
const sf::Image& ImageManager::getImage()
{
sf::Image img;
img.LoadFromFile("zeldatest.png");
ImageManager::image = img;
return ImageManager::image;
}
this gets the error
"ImageManager.cpp:21: undefined reference to `ImageManager::image'" but i have no idea how o fix it.. any insight in how to deal with static classes and properties etc would be greatly appreciated!