#include <iostream>
#include <chrono>
using namespace std;
class Length {
private:
const long double _value;
Length(long double value) : _value(value) {
}
friend Length operator"" _m(unsigned long long int value);
friend Length operator"" _m(long double value);
friend Length operator"" _km(unsigned long long int value);
friend Length operator"" _km(long double value);
public:
long double m() const {
return _value;
}
long double km() const {
return _value * 0.001;
}
Length operator-() const {
return Length(-_value);
}
Length operator+(const Length& length) const {
return Length(_value + length._value);
}
};
Length operator"" _m(unsigned long long int value) {
return Length(value);
}
// ""는 공백없이 바로 앞에 숫자를 붙이는 것을 의미
Length operator"" _m(long double value) {
return Length(value);
}
Length operator"" _km(unsigned long long int value) {
return Length(1000 * value);
}
Length operator"" _km(long double value) {
return Length(1000 * value);
}
int main() {
chrono::minutes m = 1h + 5min;
Length len = 1_m + 2_km;
cout << len.m() << "m" << endl;
cout << len.km() << "km" << endl;
cout << m.count() << endl;
}
2001m
2.001km
65