A
andrew browning
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:stream& operator << (std:stream& 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????
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:stream& operator << (std:stream& 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????