473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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?
Nov 17 '05 #1
3 1124
Try making it a "friend" function.
Nov 17 '05 #2
noleander wrote:
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
Nov 17 '05 #3
noleander wrote:
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
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Clifton M. Bean | last post by:
First, I defined three classes (listed below): =========== // 1st class =========== class PointCl { public: PointCl & operator= (const PointCl & rgh ); //define as usual assingment operator
15
by: Steve | last post by:
Hi, I hope someone can help. I have a class called cField, and another class called cFieldList. cFieldList contains a std::vector of cFields called myvec I've overloaded the subscript...
3
by: ded' | last post by:
Hello ! I've read in a magazine "reference parameter in operator= must be const, because in C++, temporary objects are const" and then my operator would not work with temporary objets. But,...
10
by: Piotr Wyderski | last post by:
Hello, is it possible to reuse a friend operator which is defined inside a class? I'd like to obtain the following behaviour: class integer { integer operator +(signed long int v) const...
3
by: Prakash Bande | last post by:
Hi, I have bool operator == (xx* obj, const string st). I have declared it as friend of class xx. I am now able to do this: xx ox; string st; if (&ox == st) { } But, when I have a vector<xx*>...
8
by: Ook | last post by:
This is my code in it's entireity: #include <iostream> using namespace std; template <typename T> class SortedList { public: friend ostream& operator<< (ostream& os, const SortedList<T>&...
4
by: Rock | last post by:
I'm in the process of writing this program for complex numbers and I use DevC++. My professor on the other hand compiles on Borland 5.5. So I ocasionally save and run my work on Borland to see if...
2
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.