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

Author Topic: Question about Time.hpp  (Read 3642 times)

0 Members and 1 Guest are viewing this topic.

GWD

  • Newbie
  • *
  • Posts: 2
    • View Profile
Question about Time.hpp
« on: December 15, 2012, 01:34:31 am »
I am currently learning C++ and SFML 2.0.  And I think I must lack some C++ knowledge because in the file Time.hpp ( http://www.sfml-dev.org/documentation/2.0/Time_8hpp_source.php )  I cannot understand why the following non-member operator functions are not declared as friend functions....

SFML_SYSTEM_API Time& operator +=(Time& left, Time right);

SFML_SYSTEM_API Time& operator -=(Time& left, Time right);

SFML_SYSTEM_API Time& operator *=(Time& left, float right);

SFML_SYSTEM_API Time& operator *=(Time& left, Int64 right);

SFML_SYSTEM_API Time& operator /=(Time& left, float right);

SFML_SYSTEM_API Time& operator /=(Time& left, Int64 right);

Since they are not friend functions, how can they mutate a Time object, when the Time class does not feature any public mutator functions, and the m_microseconds data member is private?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Question about Time.hpp
« Reply #1 on: December 15, 2012, 01:38:56 am »
Please post in Help/System (for time), and use C++ code tags.

There is no point to declare the operators as friends of sf::Time, since they can be implemented using the public API. Why didn't you have a look at Time.cpp?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Question about Time.hpp
« Reply #2 on: December 15, 2012, 08:22:36 am »
As Nexus said the implementation is in the Time.cpp file, e.g. see on GitHub.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/