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.
//Rational class with function prototypes
#ifndef RATIONAL_H
#define RATIONAL_H
#include <iostream>
usingnamespace 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
#include <iostream>
#include "Rational.h"
usingnamespace 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