class MusicManager
{
private:
std::vector<sf::Music> music;
int iCrt;
public:
void Add(const std::string& s)
{
sf::Music m;
if (!m.openFromFile(s)) return;
music.push_back(std::move(m));
}
void SetCurrent(int index)
{ iCrt = index; }
sf::Music& GetCurrent()
{ return music[iCrt]; }
};
int main()
{
MusicManager mm;
mm.Add("content/audio/music/Caught.wav");
mm.SetCurrent(0);
mm.GetCurrent().play();
getchar();
}
Since
sf::Music inherits from
sf::NonCopyable, this code will not run, giving me the error message
error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable' using Visual C++ 12.
Why is
sf::Music non-copyable? Neither
sf::Sound nor
sf::SoundBuffer has this restriction.
The only way I've found to fix this is to use an array of
sf::Music* and create each one on the stack individually.
(Sorry if this has already been explained elsewhere, but
I couldn't find it anywhere in SFML's documentation.)