|
|
A constructor can sometimes be an awkward way to express a Duration, especially in certain expressions. For example, a Duration of 1 second would be written:
Duration(0,0,0,1)
which is not very readable. For this reason, class Duration provides four static member functions (Duration::days(), Duration::hours(), Duration::minutes(), and Duration::seconds()) that allow Durations to be expressed more naturally. To illustrate their use, the expressions on either side of the equality operator yield equal values:
Duration(1,0,0,1) == Duration::days(1) + Duration::seconds(1)
The functions were made static members (rather than ordinary global functions) to avoid polluting the global namespace.