The error says it all - The shader can't be copied. Therefore, the following won't work.
void add_Shader(sf::Shader shader, std::string name)
{
// do whatever you do
}
sf::Shader a_shader;
add_Shader(a_shader, "a name"); // This will not work, because the function is using arguments by value (i.e. copying it)
A common solution to these problems is to pass arguments by reference:
void add_Shader(sf::Shader& shader, std::string name) // Note the '&' sign right after the sf::Shader
{
// do whatever you do - but a map needs to hold a shader reference too.
a_map.insert(std::pair<std::string, sf::Shader&>(name, shader));
}
sf::Shader a_shader;
add_Shader(a_shader, "a name"); // Now it should work
Now, since you probably want that your std::map holds a shader, the upper solution will also not work, because the shader that is already created needs to live long enough for reference to work, and you want your maps to have actual shaders, not references.
Maybe the best course of action is the use of smart pointers:
void add_Shader(std::string name) // Note that there is no shader here
{
// Create a shader here using smart pointers
std::unique_ptr<sf::Shader> a_Shader(new sf::Shader);
// Set everything you need for that shader here.
// You will also need to make a std::map hold "std::unique_ptr<sf::Shader>" instead of "sf::Shader",
// then insert it using the "std::move()" function:
a_map.insert(std::pair<std::string, std::unique_ptr<sf::Shader>>(name, std::move(a_Shader)));
}
add_Shader("a name"); // It should work too.
Of course there are other solutions as well, but this should be enough.
You could also pass a smart pointer as a function argument, that should work too.
Edit: minor code correction