### Error LNK 2019 and LNK 1120

Hey everyone I am currently working on a project for my C++ class and we are supposed to make a Rational class using operators and I was doing fine until I ran into these two errors. I tried looking for the solution on how to solve the LNK 2019 and LNK 1120 errors but I couldn't find a solution that could help mine. Below I have included my Rational header file, Rational .cpp file and Driver .cpp file in that respective order. Thanks in advance for anyone who tries to help me.

 12345678910111213141516171819202122232425262728 //Rational class with function prototypes #ifndef RATIONAL_H #define RATIONAL_H #include using namespace std; class Rational { public: Rational(); //Default Constructor Rational(int,int); //Constructor with paramaters ~Rational(); //Destructor void setNumerator(int); //Sets numerator void setDenominator(int); //Sets denominator void Simplify(int,int); //Simplifys fraction Rational operator+(const Rational &); //Adds two rational numbers Rational operator-(const Rational &); //Subracts two rational numbers Rational operator*(const Rational &); //Multiplys two rational numbers Rational operator/(const Rational &); //Divides two rational numbers void rationalNumber(); //prints fraction in a/b form void rationalNumber2(); //prints number in floating point format private: int numerator; //private data member for numerator int denominator; //private data member for denominator }; #endif

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 #include #include "Rational.h" using namespace std; Rational::Rational(int a,int b) { setNumerator(a); if(b>0) setDenominator(b); else { cout << "The denominator cannot be 0. It will be intialized as 1." << endl; denominator=1; } } Rational::~Rational() { } void Rational::setNumerator(int a) { numerator=a; } void Rational::setDenominator(int b) { denominator=b; } void Rational::Simplify(int numerator,int denominator) { int gcd; int smallest = numerator > denominator ? numerator : denominator; for(int i=1;i<=smallest;i++) { if(numerator%i==0&&denominator%i==0) gcd=i; } setNumerator(numerator/=gcd); setDenominator(denominator/=gcd); } void Rational::rationalNumber() { cout << "Rational Number 1=" << numerator << '/' << denominator << endl; } Rational Rational::operator+(const Rational &rhs) { Rational temp; temp.numerator=(numerator*rhs.denominator)+(rhs.numerator*denominator); temp.denominator=denominator*rhs.denominator; Simplify(temp.numerator,temp.denominator); return Rational(numerator,denominator); } Rational Rational::operator-(const Rational &rhs) { Rational temp; temp.numerator=(numerator*rhs.denominator)-(rhs.numerator*denominator); temp.denominator=denominator*rhs.denominator; Simplify(temp.numerator,temp.denominator); return Rational(numerator,denominator); } Rational Rational::operator*(const Rational &rhs) { Rational temp; temp.numerator=(numerator*rhs.numerator); temp.denominator=denominator*rhs.denominator; Simplify(temp.numerator,temp.denominator); return Rational(numerator,denominator); } Rational Rational::operator/(const Rational &rhs) { Rational temp; temp.numerator=(numerator*rhs.denominator); temp.denominator=denominator*rhs.numerator; Simplify(temp.numerator,temp.denominator); return Rational(numerator,denominator); }

 1234567891011121314151617 #include #include "Rational.h" using namespace std; int main() { int a,b,x,y; cout << "Enter the value for the first numerator and denominator" << endl; cin >> a >> b; Rational fraction1(a,b); cout << "Enter the value for the second numerator and denominator" << endl; cin >> x >> y; Rational fraction2(x,y); system("pause"); return 0; }

And these are the error messages I received
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Rational::Rational(void)" (??0Rational@@QAE@XZ) referenced in function "public: class Rational __thiscall Rational::operator+(class Rational const &)" (??HRational@@QAE?AV0@ABV0@@Z) C:\Users\Bryan\Documents\Visual Studio 2010\Projects\Project\Project\Rational.obj
Error 2 error LNK1120: 1 unresolved externals C:\Users\Bryan\Documents\Visual Studio 2010\Projects\Project\Debug\Project.exe 1
Last edited on
You've declared a default constructor for Rational, but you haven't defined it.
Can't believe I overlooked that. Thanks for helping me out I appreciate it.
You're welcome :)
Topic archived. No new replies allowed.