SOLVED
I want to overload the binary addition operator (operator+
). My compiler (Borland Builder) says that there is a declaration syntax error on operator overload definition.
Here is my code:
class Foo{
public:
double x,y,z;
Foo();
Foo(double xi, double yi, double zi) : x(xi), y(yi), z(zi) {};
friend Foo operator+(const Foo &a, const Foo &b);
} // Here is the error - no closing ';'
Foo operator+(const Foo &a, const Foo &b) //Error E2141 Declaration syntax error
{
return Foo(a.x + b.x, a.y + b.y, a.z + b.z);
}
I did same as here. Why do I get the compiler error?
EXAMPLE, SEEK FOR THE QUESTION IN COMMENTS TO THE ANSWER
Foo& operator*(const double &b, Foo& foo){
foo.x*=t;
foo.y*=t;
foo.z*=t;
return foo;
}
.
int main(){
Foo temp;
Foo bar = 4*temp;
return 0;
}