Код: Выделить всё
intоператор . Класс BКод: Выделить всё
Aоператор . Хотя компилятор неявно приводит AКод: Выделить всё
class A
{
protected:
int _a{0};
public:
A(int a) : _a(a) {}
operator int() const {return _a;}
A operator-(const A& rhs) const {return _a - rhs._a;}
};
class B
{
protected:
int _b{0};
public:
B(int b) : _b(b) {}
operator A() const {return _b;}
};
int main()
{
A a(1);
B b(2);
auto x = 2 - a; // Ok
auto y = b - a; // error: no match for ‘operator-’ (operand types are ‘B’ and ‘A’)
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... implicitly