Hey all, I am attempting to compile and run this code from two different files, my cpp file which works all fine and dandy when compiled is no problem, and a .h file
Here is the regular code which works fine:
CODE
#include <cstdlib>
#include <iostream>
#include <cctype>
using namespace std;
class Pairs
{
friend Pairs operator+(const Pairs x, const Pairs y);
friend Pairs operator*(const Pairs& x, const Pairs& y);
public:
Pairs();
Pairs(int first, int second);
friend istream& operator >> (istream& ins, Pairs& second);
friend ostream& operator << (ostream& outs, const Pairs& second);
private:
int f;
int s;
};
Pairs::Pairs() //Default Constructor
{
}
Pairs::Pairs(int first, int second) //Constructor W/ Parameters
{
}
Pairs operator+(const Pairs x, const Pairs y) //Overloaded "+" Function
{
Pairs P;
P.f = x.f + y.f; //Achieves The ( a + c ) Result
P.s = x.s + y.s; //Achieves The ( b + d ) Result
return P;
}
Pairs operator*(const Pairs& x, const Pairs& y) //Overloaded "*" Function
{
Pairs P;
P.f = x.f * y.f; //Achieves The ( a * c ) Result
P.s = x.s * y.f; //Achieves The ( b * c ) Result
return P;
}
istream& operator >> (istream& ins, Pairs& second) //Overloaded ">>" Function
{
cout << "First Number" <<endl;
ins >> second.f;
cout << "Second Number" <<endl;
ins >> second.s;
return ins;
}
ostream& operator << (ostream& outs, const Pairs& second) //Overloaded "<<" Function
{
cout << "Output Numbers:" <<endl;
outs << "(" << second.f << "," << second.s << ")" <<endl;
return outs;
}
int main(int argc, char *argv[])
{
Pairs first_pair, second_pair;
cout << "First Pair:"<<endl;
cin >> first_pair; //Takes In First Pair Of Numbers
cout << "Second Pair:" <<endl;
cin >> second_pair; //Takes In Second Pair Of Numbers
cout << "The first pair of numbers is: " <<endl;
cout << first_pair <<endl <<endl;
cout << "The second pair of numbers is: " <<endl;
cout << second_pair <<endl <<endl;
cout << "The pair after addition is as follows: "<<endl;
cout << first_pair + second_pair <<endl <<endl; //Displays The Proper Addition Of Pairs
cout << "The pair after multiplication is as follows: "<<endl; //Displays The Proper Multiplication Of Pairs
cout << first_pair * second_pair <<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
That all works fine, so I attempt to take out the class def and save it as a .h file
(.h file)
CODE
#include <cstdlib>
#include <iostream>
#include <cctype>
using namespace std;
class Pairs
{
friend Pairs operator+(const Pairs x, const Pairs y);
friend Pairs operator*(const Pairs& x, const Pairs& y);
public:
Pairs();
Pairs(int first, int second);
friend istream& operator >> (istream& ins, Pairs& second);
friend ostream& operator << (ostream& outs, const Pairs& second);
private:
int f;
int s;
};
I save the .h file as "Pairs.h" which I include in the cpp file as: #include"Pairs.h" However it doesn't seem like it's able to find the file.
Any help would be appreciated.