fork(23) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Frequency
  6. {
  7. public:
  8. void Print() const { cout << hertz << "Hz\n"; }
  9.  
  10. explicit constexpr Frequency(unsigned int h) : hertz(h) {}
  11. private:
  12. unsigned int hertz;
  13. };
  14. constexpr Frequency operator"" _Hz(unsigned long long hz)
  15. {
  16. return Frequency{hz};
  17. }
  18. constexpr Frequency operator"" _kHz(long double khz)
  19. {
  20. return Frequency{khz * 1000};
  21. }
  22.  
  23. int main()
  24. {
  25. Frequency(44100_Hz).Print();
  26. Frequency(44.1_kHz).Print();
  27. return 0;
  28. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
44100Hz
44100Hz