1

I am new to C++, and i can't figure out what's wrong in this code. Will appreciate any help.

class ResourceLoader {
protected:
    static std::map<int, Texture> textureCollection;
public:
    static Texture getSingleTexture(GameTexture gameTexture) {
        return ResourceLoader::textureCollection[gameTexture];
    }

    static void loadTexturesFromFiles() {
        ResourceLoader::loadSingleTexture(GameTexture::Character);
    }

    static void loadSingleTexture(GameTexture gameTexture) {
        Texture texture;
        texture.loadFromFile("texture.png");
        ResourceLoader::textureCollection[gameTexture] = texture;
    }
};

This results in:

undefined reference to `ResourceLoader::textureCollection'"

How is it undefined if textureCollection is declared in the protected section?

Also I don't user headers for class declaration. I know that this is not the best practice, but this speeds up the whole process..

Felix Glas
  • 15,065
  • 7
  • 53
  • 82
mrAndersen
  • 85
  • 1
  • 9

0 Answers0