I have a declaration of a class in an .hpp file:
template <typename Ressource, typename Identifier> class RessourceHolder {
public:
void load(Identifier id, const std::string& filename);
Ressource& get(Identifier id);
const Ressource& get(Identifier id) const;
private:
void insert(Identifier id, std::unique_ptr<Ressource> resource);
private:
std::map<Identifier, std::unique_ptr<Ressource>> mRessourceMap;
};
template class RessourceHolder<sf::Texture, Textures::ID>;
typedef RessourceHolder<sf::Texture, Textures::ID> TextureHolder;
which include explicit instantiation for RessourceHolder<sf::Texture,Textures::ID>
.
And I have the implementation of it in a separate .cpp file.
The problem is the following :
Later on I define a const TextureHolder
and it raises the following error :
undefined reference to `RessourceHolder<sf::Texture, Textures::ID>::get(Textures::ID) const
Why?
EDIT :
As asked, the point where the problem arise (hpp file):
class Agent{
public :
Agent(TextureHolder const& textures);
void setTexture();
const TextureHolder& mTextures;
private :
sf::Sprite mSprite;
};
(cpp file)
Agent::Agent(TextureHolder const& textures) : mTextures(textures){
setTexture();
}
void Agent::setTexture(){
mSprite.setTexture(mTextures.get(toTextureID(mType)));
}
When I remove the const specifier in agent, I don't have an error anymore