Unable to compile. Please help correct the mistakes. #include<iostream> #include
ID: 3566343 • Letter: U
Question
Unable to compile. Please help correct the mistakes.
#include<iostream>
#include<stdexcept>
using namespace std;
class Fraction
{
private:
int a;
int b;
static int GCD(const int a,const int b)
{
int min = a < b?a:b;
int i=1;
for(i=min; i>=1; i--)
if(a%i==0 && b%i==0) break;
return (i);
}
public:
Fraction(const int a, const int b)
{
if(b==0) throw invalid_argument("Error: zero denominator" );
int gcd = GCD(a,b);
this->a = a/gcd;
this->b = b/gcd;
}
friend ostream& operator<< (ostream &out, Fraction &Frac);
friend istream& operator>> (istream &in, Fraction &Frac);
friend Fraction operator+(const Fraction &f1, const Fraction &f2);
friend Fraction operator-(const Fraction &f1, const Fraction &f2);
friend bool operator==(const Fraction &f1, const Fraction &f2);
};
Complier said "
candidate constructor
not viable: requires 2 arguments, but 0 were provided
Fraction(int a,int b)"
"candidate constructor
(the implicit copy constructor) not viable: requires 1 argument, but 0
were provided
class Fraction"
Explanation / Answer
I tried compiling in codepad and it worked. No errors. Everything looks good.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.