SFML community forums
Help => General => Topic started by: davidsomen on February 18, 2011, 03:41:30 am
-
I moved the source game for a game I'd created in Visual Studios in Windows to XCode on mac but for some reason I'm getting these errors that I never got in windows :S
'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private
within this context
synthesized method 'sf::Thread::Thread(const sf::Thread&)' first required here
synthesized method 'sf::SoundStream::SoundStream(const sf::SoundStream&)' first required here
synthesized method 'sf::Music::Music(const sf::Music&)' first required here
Can someone explain what the errors mean please
-
The errors indicate that you are trying to copy the non-copyable class of sf::Music, and then fails to copy the classes sf::Music is derived from.
-
What's the solution :S Why is this an error here if it wasn't before
-
What's the solution
Don't copy sf::Music instances. Use pointers if you can't get rid of copies.
Why is this an error here if it wasn't before
It's always been an error. If you didn't get it before, it's because you never copied sf::Music instances (or either because you were using a really weird compiler).
-
It was just visual studios default compiler last time :S
Can you give me an example of how I might of copied it and how I'd use a pointer instead please. Thanks for you help
-
It was just visual studios default compiler last time
Ok, so you definitely had the error before, too.
Can you give me an example of how I might of copied it and how I'd use a pointer instead please
Right now you're doing this kind of things:
// either...
sf::Music music;
music = sf::Music(...); // --> copy there
// or...
std::vector<sf::Music> musics;
musics.push_back(sf::Music(...)); // --> copy there
The solution is to avoid these copies if possible. For example, reuse the same instance if you change the music, instead of creating a new one.
If not:
// either...
sf::Music* music;
music = new sf::Music(...);
// or...
std::vector<sf::Music*> musics;
musics.push_back(new sf::Music(...));
I can't be more relevant without knowing what you do in your code.
-
What you may not do, is calling the copy constructor or assignment operator.
sf::Music music;
sf::Music music2 = music; // copy constructor
music2 = music; // copy assignment operator
Often, copies are more hidden, for example at parameters or return types.
sf::Music Function();
void Function(sf::Music music);
Apart from that, you cannot store noncopyable objects in STL-Containers.
std::vector<sf::Music> vector;