SFML community forums

Help => General => Topic started by: davidsomen on February 18, 2011, 03:41:30 am

Title: Moving source code made in Windows to XCode on Mac Errors
Post 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
Title: Moving source code made in Windows to XCode on Mac Errors
Post by: Lalaland on February 18, 2011, 06:41:52 am
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.
Title: Moving source code made in Windows to XCode on Mac Errors
Post by: davidsomen on February 18, 2011, 11:53:43 am
What's the solution :S Why is this an error here if it wasn't before
Title: Moving source code made in Windows to XCode on Mac Errors
Post by: Laurent on February 18, 2011, 12:11:35 pm
Quote
What's the solution

Don't copy sf::Music instances. Use pointers if you can't get rid of copies.

Quote
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).
Title: Moving source code made in Windows to XCode on Mac Errors
Post by: davidsomen on February 18, 2011, 01:45:02 pm
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
Title: Moving source code made in Windows to XCode on Mac Errors
Post by: Laurent on February 18, 2011, 01:53:42 pm
Quote
It was just visual studios default compiler last time

Ok, so you definitely had the error before, too.

Quote
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:
Code: [Select]
// 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:
Code: [Select]
// 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.
Title: Moving source code made in Windows to XCode on Mac Errors
Post by: Nexus on February 18, 2011, 01:55:08 pm
What you may not do, is calling the copy constructor or assignment operator.
Code: [Select]
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.
Code: [Select]
sf::Music Function();
void Function(sf::Music music);

Apart from that, you cannot store noncopyable objects in STL-Containers.
Code: [Select]
std::vector<sf::Music> vector;