fork(3) download
  1. #include <iostream>
  2.  
  3. class T {
  4. public:
  5. int a, b;
  6. T (int _a = 0, int _b = 0) : a(_a), b(_b) { } // konwersja int -> T, nie moze byc explicit
  7.  
  8. friend T operator+ (const T &a, const T &b) {
  9. return T(a.a + b.a, a.b + b.b);
  10. }
  11.  
  12. operator bool () { return (this->b != 0 || this->a != 0); } // bez tego dziala (?)
  13.  
  14. operator int() = delete; // zabroniona konwersja T -> int (!)
  15. };
  16.  
  17. int main () {
  18. T a(1, 3);
  19. std::cout << (a + 1).a << ' ' << (a + 1).b;
  20. return 0;
  21. }
Compilation error #stdin compilation error #stdout 0s 3140KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:19:21: error: ambiguous overload for 'operator+' (operand types are 'T' and 'int')
     std::cout << (a + 1).a << ' ' << (a + 1).b;
                     ^
prog.cpp:19:21: note: candidates are:
prog.cpp:19:21: note: operator+(int, int) <built-in>
prog.cpp:8:14: note: T operator+(const T&, const T&)
     friend T operator+ (const T &a, const T &b) {
              ^
prog.cpp:19:41: error: ambiguous overload for 'operator+' (operand types are 'T' and 'int')
     std::cout << (a + 1).a << ' ' << (a + 1).b;
                                         ^
prog.cpp:19:41: note: candidates are:
prog.cpp:19:41: note: operator+(int, int) <built-in>
prog.cpp:8:14: note: T operator+(const T&, const T&)
     friend T operator+ (const T &a, const T &b) {
              ^
stdout
Standard output is empty