SFML community forums

Help => General => Topic started by: Helios101 on January 30, 2014, 01:21:03 am

Title: .
Post by: Helios101 on January 30, 2014, 01:21:03 am
.
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: eigenbom on January 30, 2014, 01:22:25 am
You need to pass by reference (or pointer).

Code: [Select]
void Gameplay(sf::RenderWindow& Display)
{
   ...
}

In general, read up about pass by value and pass by reference, as they are important C++ concepts. :D
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: zsbzsb on January 30, 2014, 02:23:20 am
In general, read up about pass by value and pass by reference, as they are important C++ concepts. :D

This is what you need to do, instead of coming here asking very, very basic C++ questions  ;)


sf::RenderWindow& Window(sf::VideoMode(screenDimension.x, screenDimension.y), "Games States");

You can't initialize references.....  :P


int main()
{
     sf::RenderWindow Window(sf::VideoMode(screenDimension.x, screenDimension.y), "Games States");
     DoSomething(Window);
}
void DoSomething(sf::RenderWindow& MyWindowReference)
{
}
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: Veltas on January 30, 2014, 02:33:32 am
In general, read up about pass by value and pass by reference, as they are important C++ concepts. :D
This is what you need to do, instead of coming here asking very, very basic C++ questions  ;)

No, disregard zsbzsb, he's old and grumpy. You should come here and ask plenty of questions that could be answered with a basic grasp of C++, because it's not insane to try and make C++ more interesting while trying to learn it.

EDIT: I'd like to point out that this above line was not as abrasive as it sounds, me and zsbzsb were mucking around a bit on #sfml.

Good luck learning C++ and I hope to see something productive of your SFML usage some day.
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: Nexus on January 30, 2014, 06:54:33 pm
No, disregard zsbzsb, he's old and grumpy.
Don't start to offend other people just because you don't like their opinion. Especially when their tone is friendly and even helpful (note how zsbzsb also showed the correct code).

zsbzsb's point is a good one: You can't learn SFML when you lack the basic understanding of the C++ language. I know there are plenty of people who don't believe this, they'll always make their lives harder than necessary. And I really mean that, because I've made exactly the same experience when I began... In hindsight I could have saved so much time and troubles ;)

See also this post (http://en.sfml-dev.org/forums/index.php?topic=10887.msg75152#msg75152) for a more detailed explanation.
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: zsbzsb on January 30, 2014, 06:59:16 pm
Don't start to offend other people just because you don't like their opinion. Especially when their tone is friendly and even helpful (note how zsbzsb also showed the correct code).

No worries, we were joking about this a little bit on IRC  :D

And speaking of that, Nexus you should come join us (irc.boxbox.org #sfml) and since you are the "leader" of SFML we can discuss things  ;)
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: Jesper Juhl on January 30, 2014, 09:32:41 pm
Although other people have already given good answers on what to do to fix your code it seems to me that no one actually answered the original question "What is sf::NonCopyable::NonCopyable". So let me just briefly do that.

sf::NonCopyable is a class that, if you inherit from it, will make it impossible to create a copy of an instance of your derived class. It does this by making the copy-constructor and copy-assignment operator private.
This is useful when copying an instance of a class would lead to incorrect or undesirable behaviour.

The documentation for the class is available here: http://www.sfml-dev.org/documentation/2.1/classsf_1_1NonCopyable.php (http://www.sfml-dev.org/documentation/2.1/classsf_1_1NonCopyable.php).
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: Veltas on January 31, 2014, 12:01:07 am
Don't start to offend other people just because you don't like their opinion.

Yes, sorry Nexus: this was a silly joke with zsbzsb and I've edited my comment to make that clear. I don't want to drag down the reputation of the SFML forum at all.

zsbzsb's point is a good one: You can't learn SFML when you lack the basic understanding of the C++ language. I know there are plenty of people who don't believe this, they'll always make their lives harder than necessary. And I really mean that, because I've made exactly the same experience when I began... In hindsight I could have saved so much time and troubles ;)

I think it really depends on the person: I found C++ easier when trying to learn from the ground up with a good book. But I know people who dove straight into trying to use libraries etc. and still had a good time of it. It doesn't sound implausible to me.

Also, at what stage have you learnt basic C++? He may well have learnt about basic structure, functions and classes without having properly taken in references by coincidence. Should one completely abstain from trying out things until they're fully up to date with ISO/IEC 14882:2011?
Title: Re: What is sf::NonCopyable::NonCopyable'?
Post by: Rosme on January 31, 2014, 07:01:47 pm
zsbzsb's point is a good one: You can't learn SFML when you lack the basic understanding of the C++ language. I know there are plenty of people who don't believe this, they'll always make their lives harder than necessary. And I really mean that, because I've made exactly the same experience when I began... In hindsight I could have saved so much time and troubles ;)

Also, at what stage have you learnt basic C++? He may well have learnt about basic structure, functions and classes without having properly taken in references by coincidence. Should one completely abstain from trying out things until they're fully up to date with ISO/IEC 14882:2011?
Yes haha! But in all seriousness, no. Sure experimenting with librairies is a good thing, but they should know correctly the fundamentals of C++. Reference is a fundamental. I'm not saying they should not all idioms and produce perfect idiomatic code, but they should know about reference, operator overloading(at least the rules of three(which would have explain a little bit the problem with the non-copyable class)), and other things like that.