Since it's a expensive resource to load, why not make its constructor explicit to avoid errors.
I was programming a resource manager (which returns a sf::Texture&) and expended about 15 minutes to notice this error:
sf::Texture texture = ResourceManager::getTexture("file.png");
sf::Sprite sprite(texture);
ResourceManager::freeTexture("file.png");
// sprite still displaying even if the Resource Manager texture was freed
The reason of the sprite working
fine is because sf::Texture has a non-explicit copy constructor. So it was alocating twice the memory required for an image.
The intended behaviour was to free the texture and no image should be displayed
The correct code for this is:
sf::Texture& texture = ResourceManager::getTexture("file.png");
I know everything is right, but it would be better if that triggers an error.
If you want to copy a texture still would be possible with the following code:
sf::Texture& texture(ResourceManager::getTexture("file.png"));
Same with other expensive resources, as Image, etc.