fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. class Test {
  7. public:
  8. Test(int x = 0):val_(x){ cout << "Test(" << x << ")\n"; }
  9. ~Test() { cout << "~Test(" << val_ <<")\n"; }
  10.  
  11. operator int() const { cout << "Test::operator int(" << val_ <<")\n"; return val_; }
  12. operator bool() const { cout << "Test::operator bool(" << val_ <<")\n"; return val_; }
  13.  
  14. private:
  15. int val_ = 0;
  16. };
  17.  
  18.  
  19. int main(int argc, const char * argv[])
  20. {
  21. Test t(5);
  22. if (t)
  23. {
  24. cout << "true\n";
  25. }
  26. }
  27.  
  28.  
Success #stdin #stdout 0s 4316KB
stdin
Standard input is empty
stdout
Test(5)
Test::operator bool(5)
true
~Test(5)