#include <iostream> #include<math.h> using namespace std; class fractionType { f
ID: 3551020 • Letter: #
Question
#include <iostream>
#include<math.h>
using namespace std;
class fractionType
{
friend ostream &operator <<(ostream &, const fractionType &);
friend istream &operator >>(istream &,fractionType &);
public:
fractionType operator+(fractionType x);
fractionType operator-(fractionType x);
fractionType operator*(fractionType x);
fractionType operator/(fractionType x);
int fractionType::gcd();
void fractionType::reduce();
private:
int num,den;
};
i dont know why keep error on this part??
Explanation / Answer
When you are declaring the function prototype, or defining the member function inside the class you don't have to bind the function to the class using scope resolution operator. When you are defining the member function outside the class, u've to use this operator to bind to the given class name. The correct code is as follows (the corrected statements have been commented):
#include <iostream>
#include<math.h>
using namespace std;
class fractionType
{
friend ostream &operator <<(ostream &, const fractionType &);
friend istream &operator >>(istream &,fractionType &);
public:
fractionType operator+(fractionType x);
fractionType operator-(fractionType x);
fractionType operator*(fractionType x);
fractionType operator/(fractionType x);
int gcd(); //changed
void reduce(); //changed
private:
int num,den;
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.