Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1898318
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:45:02+00:00 2026-05-17T06:45:02+00:00

I am making a fraction class for a school project, and my brain is

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:45:03+00:00Added an answer on May 17, 2026 at 6:45 am

    Sounds like you tried to declare friend ostream &operator<<(…) const; . The important thing about friends is that they are not members. A friend function exists outside the scope of the class, even if it is defined inside the class {} block. In other words, you are declaring a function ::operator<<(), not fraction::operator<<(). And only member functions can have that trailing const, since it modifies the type of this.

    Fact is, operator<< for output usually shouldn’t be a friend anyway. It just gets the value and forwards it to the stream… that shouldn’t require any special permission! Same applies to operator<.

    Take the functions outside the class block entirely. There’s no way your TA can complain about your design using friend less often.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom Fraction class, which I'm using throughout my whole project. It's
While making an edit to a class with a long history, I was stymied
Making a simple Java code for Blackjack and need some advice. OK I am
Making an image draggable does some pretty wacky things when the image is larger
Making game of life I need to a have a grid that is 30x20
making a call to a web service method with nusoap returns an error array(3)
Making a social media app. I have a main viewFlipper with several views therein.
I have recently begun to develop a game in Haxe which targets the Flash
So I've read over several questions here about the pros and cons of using
I'm playing with the following application using the HTML Canvas: http://driz.co.uk/particles/ At the moment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.