Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
noleander - 14 May 2005 07:21 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.