fork download
  1. #include <cmath>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Val {
  6. int a;
  7. float b;
  8. public:
  9. Val& operator= (const int _a) {a = _a; b = _a + fmod(b, 1.0F); return *this;}
  10. Val& operator= (const float _b) {b = _b; a = trunc(_b); return *this;}
  11. operator int() {return a;}
  12. operator float() {return b;}
  13. };
  14.  
  15. int main() {
  16. Val foo;
  17.  
  18. foo = 1.3F;
  19.  
  20. cout << static_cast<int>(foo) << endl << static_cast<float>(foo) << endl;
  21.  
  22. foo = 13;
  23.  
  24. cout << static_cast<int>(foo) << endl << static_cast<float>(foo) << endl;
  25. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
1
1.3
13
13.3