Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: copy constructor?  (Read 4999 times)

0 Members and 1 Guest are viewing this topic.

exessuz

  • Guest
copy constructor?
« on: January 19, 2016, 09:34:19 pm »
Hi guys, first of all thank you for making such a great library.
I hope this is the right place to ask or request this. I would like to know if you didnt add copy constructors in classes such as sprite or text for a reason?

Thank you.


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: copy constructor?
« Reply #1 on: January 19, 2016, 09:55:50 pm »
There's no need to implement a copy constructor if the compiler-generated one does the right thing. See Rule of Three.

By the way, it's generally a good idea to design classes in a way they're able to copy themselves without explicitly telling them how. To achieve deep copies through (possibly polymorphic) pointers, things like this are very helpful. They can decrease your code by dozens of lines, and with them the maintenance costs and errors.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: copy constructor?
« Reply #2 on: January 19, 2016, 09:56:10 pm »
Huh? ??? sf::Sprite and sf::Text are copyable.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

exessuz

  • Guest
Re: copy constructor?
« Reply #3 on: January 19, 2016, 10:37:26 pm »
Nexus thank you for the quick answer! Ill keep that in mind.

Huh? ??? sf::Sprite and sf::Text are copyable.

enlighten me please :) how can I make a copy of an sf::Sprite

Thank you.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: copy constructor?
« Reply #4 on: January 19, 2016, 10:46:59 pm »
You should read a good C++ book, those are absolute basics.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: copy constructor?
« Reply #5 on: January 20, 2016, 04:19:13 pm »
enlighten me please :) how can I make a copy of an sf::Sprite

Thank you.

You can always use the copy constructor without it being declared and defined by the programmer because your compiler will generate it for you with the default semantics, as long as the programmer does not forbid the default generated ones ( =delete; in C++11).

This is not visible because the default versions of dtor, copy ctor, copy assignment, move ctor and move assignment are not exposed in the API. This is accounted for in C++11 too, where you can explicitly define them in the API with =default; (which SFML doesn't actually do because it doesn't use C++11 yet)

And yes, you should read a book about the C++ basics.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: copy constructor?
« Reply #6 on: January 22, 2016, 07:21:02 pm »
This is accounted for in C++11 too, where you can explicitly define them in the API with =default; (which SFML doesn't actually do because it doesn't use C++11 yet)
SFML wouldn't do it in C++11 either, as redundant =default declarations only add code without any advantage. This language feature makes sense when the Rule Of Three/Five doesn't apply because some functions are manually written, while others should still be default-generated.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: