#include <iostream>
class T {
public:
int a, b;
T (int _a = 0, int _b = 0) : a(_a), b(_b) { } // konwersja int -> T, nie moze byc explicit
friend T operator+ (const T &a, const T &b) {
return T(a.a + b.a, a.b + b.b);
}
operator bool () { return (this->b != 0 || this->a != 0); } // bez tego dziala (?)
operator int() = delete; // zabroniona konwersja T -> int (!)
};
int main () {
T a(1, 3);
std::cout << (a + 1).a << ' ' << (a + 1).b;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgVCB7CnB1YmxpYzoKICAgIGludCBhLCBiOwogICAgVCAoaW50IF9hID0gMCwgaW50IF9iID0gMCkgOiBhKF9hKSwgYihfYikgeyB9IC8vIGtvbndlcnNqYSBpbnQgLT4gVCwgbmllIG1vemUgYnljIGV4cGxpY2l0CgogICAgZnJpZW5kIFQgb3BlcmF0b3IrIChjb25zdCBUICZhLCBjb25zdCBUICZiKSB7CiAgICAgICAgcmV0dXJuIFQoYS5hICsgYi5hLCBhLmIgKyBiLmIpOwogICAgfQoKICAgIG9wZXJhdG9yIGJvb2wgKCkgeyByZXR1cm4gKHRoaXMtPmIgIT0gMCB8fCB0aGlzLT5hICE9IDApOyB9IC8vIGJleiB0ZWdvIGR6aWFsYSAoPykKCiAgICBvcGVyYXRvciBpbnQoKSA9IGRlbGV0ZTsgLy8gemFicm9uaW9uYSBrb253ZXJzamEgVCAtPiBpbnQgKCEpCn07CgppbnQgbWFpbiAoKSB7CiAgICBUIGEoMSwgMyk7CiAgICBzdGQ6OmNvdXQgPDwgKGEgKyAxKS5hIDw8ICcgJyA8PCAoYSArIDEpLmI7CiAgICByZXR1cm4gMDsKfQ==
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) {
^