fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7. class A
  8. {
  9. int x;
  10. public:
  11. A() : x(0)
  12. {}
  13. A(int a) : x(a)
  14. {}
  15. ~A()
  16. {}
  17. A operator + (const A &rhs)
  18. {
  19. return A(x+rhs.x);
  20. }
  21.  
  22. operator int() const
  23. {
  24. return x;
  25. }
  26. };
  27.  
  28. int main()
  29. {
  30. A a = 4, c;
  31. c = 6 + a;
  32.  
  33. std::cout << c << std::endl;
  34.  
  35. c = a + 6;
  36.  
  37. std::cout << c << std::endl;
  38.  
  39. return 0;
  40. }
Compilation error #stdin compilation error #stdout 0s 3460KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:35:11: error: ambiguous overload for 'operator+' (operand types are 'A' and 'int')
     c = a + 6;
           ^
prog.cpp:35:11: note: candidate: operator+(int, int) <built-in>
prog.cpp:17:8: note: candidate: A A::operator+(const A&)
     A  operator + (const A &rhs)
        ^
stdout
Standard output is empty