I've got some source code that includes vector and matrix classes (or
structures) that have addition and subtraction operators. This source code
compiles on five different Unix platforms, but I'm getting a compiler error
on Vis C++. The error is:
"binary operator + has too many parameters".
Here is the offending code fragment:
class ground_point_struct {
. . .
ground_point_struct // return value
operator +( // addition operator
ground_point_struct &gp1, // ground point
ground_point_struct &gp2 ) // ground point to subtract
{ .... }
Does anyone have any idea why Vis C++ wont compile this addition method?
Gabest - 14 May 2005 07:27 GMT
Try making it a "friend" function.
Carl Daniel [VC++ MVP] - 14 May 2005 07:55 GMT
> I've got some source code that includes vector and matrix classes (or
> structures) that have addition and subtraction operators. This
[quoted text clipped - 15 lines]
> Does anyone have any idea why Vis C++ wont compile this addition
> method?
Because it's not legal C++ code.
operator+ can be either a member function or a namespace-scoped function.
As a member function, it must have a single parameter (*this is the other
parameter). As a namespace-scoped function it must have two parameters.
Move the function declaration outside the class and make it a friend of the
class if necessary (if it needs to access non-public members of the class).
-cd
Arnaud Debaene - 14 May 2005 10:41 GMT
> I've got some source code that includes vector and matrix classes (or
> structures) that have addition and subtraction operators. This
[quoted text clipped - 12 lines]
> ground_point_struct &gp2 ) // ground point to subtract
> { .... }
How would you call this operator since it has 3 arguments (gp1, gp2 an
implicit this, since the operator is a member function) ??
Arnaud
MVP - VC