Computing.Net > Forums > Programming > C++ Problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ Problem

Reply to Message Icon

Name: Den
Date: September 19, 2002 at 16:49:30 Pacific
OS: Win2k
CPU/Ram: p4
Comment:

I got this error every time I compiler operator-():
"error C2804: binary 'operator +' has too many parameters"

class Fraction
{
public:
Fraction ()
{ num = 0; deno = 0, result = 0;};
Fraction(int x, int y)
{ num = x, deno = y;};
Fraction operator +(Fraction& x, Fraction& y); //this line generates the above erro
void menu();
double num, deno, result;
};



Sponsored Link
Ads by Google

Response Number 1
Name: Jeff J
Date: September 19, 2002 at 18:10:33 Pacific
Reply:

Your overload of the + operator would be perfectly fine if it was defined outside the class (as that requires two parameters). Within a class definition, the left-hand-side operand is already assumed to be 'this', so only the right-hand-side operand can be specified as a singular parameter.

You can either move the function outside the class, or remove one of the parameters in the member function.

Cheers


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ Problem

C++ Problem www.computing.net/answers/programming/c-problem/13694.html

a C problem www.computing.net/answers/programming/a-c-problem/13208.html

C++ Problem Question www.computing.net/answers/programming/c-problem-question/3790.html