SFML community forums

Help => System => Topic started by: GWD on December 15, 2012, 01:34:31 am

Title: Question about Time.hpp
Post by: GWD 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 (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?
Title: Re: Question about Time.hpp
Post by: Nexus 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?
Title: AW: Question about Time.hpp
Post by: eXpl0it3r on December 15, 2012, 08:22:36 am
As Nexus said the implementation is in the Time.cpp file, e.g. see on  GitHub (https://github.com/SFML/SFML/blob/master/src/SFML/System/Time.cpp).