I have a class with conversions konw -> int, double -> konw:
class konw {
double re, im;
public:
konw() : re(0.0), im(0.0) {}
konw(double r, double i = 0.0) : re(r), im(i) {}
operator int() {return re;}
konw operator+(konw a) {konw wynik; wynik.re = re + a.re; wynik.im = im + a.im; return wynik;}
};
I mainly test these conversions with the overloaded + operator
konw zesp(3.1, 0.6);
int ssuma = zesp + 6;
The compiler reports an error while working on the last attached line saying that:
ambiguous overload for 'operator+' in 'zesp + 6'
As far as I read, if there are several ways to call an overloaded function, the compiler chooses the shortest one. Of course, there should be one and only such way. I could find two ways to call the + operator:
zespkonw โ int conversion variable and calloperator+(int, int)- conversion constant
6int-> double-> konw and callkonw::operator+(konw)
1- , 2-, Imo , . ? ?