I am making a fraction class for a school project, and my brain is frying. I was told to overload the << and >> operators through the friend keyword. But I'm getting errors for this.
I've posted the relevant code here: http://pastebin.com/NgCABGJ2
The errors include: error C2270: '<<' : modifiers not allowed on nonmember functions (this error is for all the ones that are declared as friends)
This was at the operator< definition. error C2333: 'Fraction::operator <' : error in function declaration; skipping function body
There's 46 in all... this is a nightmare.
EDIT:
Thanks, I solved almost all the errors, but there's still 3
error C2664: 'Fraction::Fraction(const Fraction &)' : cannot convert parameter 1 from 'int' to 'const Fraction &' Occurs at this statement:
Fraction<int> test1, test2, test3(10);
error C2248: 'Fraction::operator ==' : cannot access private member declared in class 'Fraction' error C2248: 'Fraction::operator <' : cannot access private member declared in class 'Fraction'
I don't understand these two, but it occurs at these statements:
if (test1 == test2)
cout << "\nTest1 is equal to Test2";
if (test1 < test2)
cout << "\nTest1 is less than Test2";
Thanks!
<><><>>EDIT2<<><><>
I fixed the other private access errors, but now i have some reaaaaaaaally bizarre errors:
Full code: http://pastebin.com/MVrB67SR
Errors:
Error 1 error LNK2001: unresolved external symbol "class Fraction __cdecl operator-(class Fraction const &,class Fraction const &)" (??G@YA?AV?$Fraction@H@@ABV0@0@Z) Error 2 error LNK2001: unresolved external symbol "class Fraction __cdecl operator+(class Fraction const &,class Fraction const &)" (??H@YA?AV?$Fraction@H@@ABV0@0@Z) Error 3 error LNK2001: unresolved external symbol "class Fraction __cdecl operator/(class Fraction const &,class Fraction const &)" (??K@YA?AV?$Fraction@H@@ABV0@0@Z) c:\Users\caleb jares\documents\visual studio 2010\Projects\Solution11-5\Solution11-5\Solution11-5.obj Error 4 error LNK2001: unresolved external symbol "class Fraction __cdecl operator*(class Fraction const &,class Fraction const &)" (??D@YA?AV?$Fraction@H@@ABV0@0@Z) Error 5 error LNK2001: unresolved external symbol "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > const &,class Fraction)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@ABV01@V?$Fraction@H@@@Z) Error 6 error LNK2001: unresolved external symbol "class std::basic_istream > & __cdecl operator>>(class std::basic_istream > const &,class Fraction)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@ABV01@V?$Fraction@H@@@Z) Error 7 error LNK1120: 6 unresolved externals
Again, thanks for help!