diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-02-16 22:26:44 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-02-16 22:26:44 +0100 |
commit | 94a56e0a7bb951845bc7a3cde055117f374102c2 (patch) | |
tree | f8a1850bd9bf9cb80c0fa800d6f0664c46c6e262 /C++.wiki | |
parent | Remove bad strap-centos page (diff) | |
download | wiki-public-94a56e0a7bb951845bc7a3cde055117f374102c2.tar.gz wiki-public-94a56e0a7bb951845bc7a3cde055117f374102c2.tar.xz |
ons 16 feb 2022 22:26:44 CET
Diffstat (limited to 'C++.wiki')
-rw-r--r-- | C++.wiki | 56 |
1 files changed, 55 insertions, 1 deletions
@@ -1,6 +1,7 @@ = Contents = - [[#C++ Examples|C++ Examples]] - - [[#C++ Examples#Friend operator|Friend operator]] + - [[#C++ Examples#Friend operator|Friend operator]] + - [[#C++ Examples#Time Header|Time Header]] = C++ Examples = @@ -34,3 +35,56 @@ int main () { std::cout << t << std::endl; } }}} + +== Time Header == + +{{{c++ +#pragma once + +#include <ostream> + +enum timetype { + _day, _hour, _minute, _second +}; + +class Time { +private: + + int _days = 0; + int _hours = 0; + int _minutes = 0; + int _seconds = 0; + +public: + Time() { }; + Time(int n, timetype type); + + int to_seconds() const; + + friend std::ostream& operator<<(std::ostream&, const Time&); + friend Time operator * (int, Time); + + Time operator + (const Time&); + Time operator , (const Time& t) { return *this + t; } + Time operator && (const Time& t) { return *this + t; } +}; + +#define days * Time(1, _day) +#define day days +#define hours * Time(1, _hour) +#define hour hours +#define minutes * Time(1, _minute) +#define minute minutes +#define seconds * Time(1, _second) +#define second seconds + +int main() { + std::cout + << 5 days << std::endl + << 7 minutes << std::endl + << (5 days and 3 seconds) << std::endl + << (7 days, 7 minutes and 3 seconds) << std::endl + << (9 hours and 1 second) << std::endl + ; +} +}}} |