Operator + compiles on Unix, but not Vis C++

G

Guest

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?
 
C

Carl Daniel [VC++ MVP]

noleander said:
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?

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
 
A

Arnaud Debaene

noleander said:
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
{ .... }

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top