fork download
  1. #include <iostream>
  2.  
  3. struct _int {
  4. int i;
  5. _int(int i) : i(i) {}
  6. operator int() {
  7. return i;
  8. }
  9. ~_int() {
  10. std::cout << "~_int\n";
  11. }
  12. };
  13.  
  14. struct _float {
  15. float f;
  16. _float(float f) : f(f) {}
  17. operator _int() {
  18. return _int((int) f);
  19. }
  20. ~_float() {
  21. std::cout << "~_float\n";
  22. }
  23. };
  24.  
  25. void print_int(const _int& i) {
  26. std::printf("%i\n", i.i);
  27. }
  28.  
  29. int main(int argc, const char* args[]) {
  30. print_int(_float(3.141));
  31. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
3
~_int
~_float