Cześć
Ostatnio próbowałem ogarnąć operatory , poczytałem trochę na necie, popisałem i natrafiłem na problem (pewnie dość prosty) którego nie umiem rozwiązać
Przy próbie utworzenia obiektu za pomocą dodania dwóch innych pojawia się bład : invalid operands to binary expression ('Complex' and 'Complex')
Jakby ktoś wytłumaczył dlaczego to nie zadziała a nie wysyłał materiały albo dokumentacje byłbym wdzięczny
#include <iostream>
using namespace std;
class Complex {
friend Complex operator + (Complex const &);
private:
int real, imag;
public:
Complex(int,int);
void print() { cout << real << " + i" << imag << endl; }
};
Complex::Complex(int r , int i )
{
real = r ;
imag = i ;
}
Complex operator + (Complex const &obj)
{
Complex tmp(0,0);
tmp.real=tmp.real + obj.real;
tmp.imag=tmp.imag + obj.imag;
return tmp;
}
int main()
{
Complex c1(10, 5), c2(2, 4) , c4(1,1);
Complex c3 = c1 + c2 ;//+ c4;
//c3.print();
}