I am getting an istream overloading error that looks like this:
error: no match for 'operator>>' in 'ins >>
target>abrowning_rational::Rational::numerator'
Below is the .h file:
#ifndef RATIONAL
#define RATIONAL
#include <iostream>
namespace abrowning_rational{
class Rational{
public:
//CONSTRUCTOR for the rational class
Rational();
Rational(int a, int b);
//CONSTANT MEMBER FUNCTIONS for the Rational class
int getNum () const {return numerator;} // Gets numerator
int getDen () const {return denominator;} // Gets denominator
//MODIFICATION MEMBER FUNCTIONS for the rational class
int gcd(int a, int b); // returns GCD using euclidean algorithm
//Friend Functions
friend std::istream& operator >> (std::istream& ins, const
Rational& target);
private:
int numerator;
int denominator;
};
//NONMEMBER FUNCTIONS for the Rational class
Rational operator + (const Rational& r1, const Rational& r2);
Rational operator  (const Rational& r1, const Rational& r2);
Rational operator * (const Rational& r1, const Rational& r2);
Rational operator / (const Rational& r1, const Rational& r2);
bool operator == (const Rational& r1, const Rational& r2);
bool operator != (const Rational& r1, const Rational& r2);
bool operator >= (const Rational& r1, const Rational& r2);
bool operator <= (const Rational& r1, const Rational& r2);
bool operator > (const Rational& r1, const Rational& r2);
bool operator < (const Rational& r1, const Rational& r2);
std::ostream& operator << (std::ostream& outs, const Rational&
source);
}
#endif //RATIONAL_H
~
And now the implementation of the overloaded input operator:
std::istream& operator >> (std::istream& ins, const Rational& target){
//Postcondition: target is read from ins. the return value is
//istream ins. Library facility used is iostream
ins >> target.numerator >> target.denominator;
return ins;
}
If i comment out the " ins >> target.numerator >>
target.denominator; " line
the error goes away. Can someone please help me find my way home???? 8 2554
andrew browning wrote: I am getting an istream overloading error that looks like this:
error: no match for 'operator>>' in 'ins >> target>abrowning_rational::Rational::numerator'
Below is the .h file:
#ifndef RATIONAL #define RATIONAL #include <iostream>
namespace abrowning_rational{
class Rational{
public:
//CONSTRUCTOR for the rational class Rational(); Rational(int a, int b);
//CONSTANT MEMBER FUNCTIONS for the Rational class int getNum () const {return numerator;} // Gets numerator int getDen () const {return denominator;} // Gets denominator
//MODIFICATION MEMBER FUNCTIONS for the rational class int gcd(int a, int b); // returns GCD using euclidean algorithm
//Friend Functions friend std::istream& operator >> (std::istream& ins, const Rational& target);
private:
int numerator; int denominator;
};
//NONMEMBER FUNCTIONS for the Rational class Rational operator + (const Rational& r1, const Rational& r2); Rational operator  (const Rational& r1, const Rational& r2); Rational operator * (const Rational& r1, const Rational& r2); Rational operator / (const Rational& r1, const Rational& r2); bool operator == (const Rational& r1, const Rational& r2); bool operator != (const Rational& r1, const Rational& r2); bool operator >= (const Rational& r1, const Rational& r2); bool operator <= (const Rational& r1, const Rational& r2); bool operator > (const Rational& r1, const Rational& r2); bool operator < (const Rational& r1, const Rational& r2); std::ostream& operator << (std::ostream& outs, const Rational& source);
}
#endif //RATIONAL_H ~
And now the implementation of the overloaded input operator:
std::istream& operator >> (std::istream& ins, const Rational& target){ //Postcondition: target is read from ins. the return value is
//istream ins. Library facility used is iostream ins >> target.numerator >> target.denominator;
return ins; }
If i comment out the " ins >> target.numerator >> target.denominator; " line the error goes away. Can someone please help me find my way home????
Please remove irrelevant parts, then post _the_entire_code_ that fails
to compile. The reason is most likely in the fact that you declare the
friend function one way and define it some other way. Since you don't
show how (or, rather, where), nothing special can be said about it.
V

Please remove capital As from my address when replying by mail
 Remove the 'const' from the second parameter of the operator >>()
definition.
 Declare operator >> as friend of Rational otherwise it will not have
access to its 'numerator' and 'denominator' members which are private.
Ok you already have the friend, so just remove the const ;)
thanks. i removed the const but then got an errors saying the
numerator and denominator were private and that there was an error
within that context:
Rational.cpp: In function 'std::istream&
abrowning_rational::operator>>(std::istream&,
abrowning_rational::Rational&)':
Rational.h:32: error: 'int abrowning_rational::Rational::numerator' is
private
Rational.cpp:36: error: within this context
Rational.h:33: error: 'int abrowning_rational::Rational::denominator'
is private
Rational.cpp:36: error: within this context
Did you also remove the const from the friend declaration?
just did and it rocked!!!! thanks ever so much for your help, it was
very gracious of you This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Terje Slettebų 
last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been
discussed before, I'd appreciate a pointer to it. I again haven't found it
in a search of the PHP groups.
The PHP...

by: Hendrik Schober 
last post by:
Hi,
I have a problem, that boils down to the following code:
#include <iostream>
#include <typeinfo>
class Test1 {};
class Test2 {};
class Test3 {};

by: Pmb 
last post by:
I've been working on creating a Complex class for my own learning purpose
(learn through doing etc.). I'm once again puzzled about something. I can't
figure out how to overload the assignment...

by: WittyGuy 
last post by:
Hi,
What is the major difference between function overloading and function
templates?
Thanks!
http://www.gotw.ca/resources/clcm.htm for info about ]

by: 
last post by:
Hi,
Why can I not overload on just the return type?
Say for example.
public int blah(int x)
{
}

by: Jerry Fleming 
last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone
says that the four operators can only be overloaded with class member
functions instead of global (friend) functions: (), ,...

by: jakester 
last post by:
I am using Visual C++ 2007 to build the code below. I keep getting
linkage error. Could someone please tell me what I am doing wrong? The
code works until I start using namespace for my objects.
...

by: Pramod 
last post by:
I have one question. Can I catch exception in function overloading.In
my programm i want to create two function with same signature and same
return type. I know its not possible...can i use...

by: Colonel 
last post by:
It seems that the problems have something to do with the overloading of
istream operator ">>", but I just can't find the exact problem.
// the declaration
friend std::istream &...

by: =?Utf8?B?VkIgRGV2ZWxvcGVy?= 
last post by:
Overloading of the unary ++ operator in vb.net is not working. It show error:
Operator declaration must be one of: +, , *, \, /, ^, &, Like, Mod, And,
Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=,...

by: Aliciasmith 
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...

by: tracyyun 
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...

by: giovanniandrean 
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...

by: NeoPa 
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...

by: Teri B 
last post by:
Hi, I have created a subform Roles. In my course form the user selects the roles assigned to the course.
0netomany. One course many roles.
Then I created a report based on the Course form and...

by: isladogs 
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...

by: nia12 
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...

by: NeoPa 
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

by: SueHopson 
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
 