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 6833601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:59:54+00:00 2026-05-26T22:59:54+00:00

I am working on Exercise 11.11 on page 498 of C++ How to program

  • 0

I am working on Exercise 11.11 on page 498 of C++ How to program 8th edition.

The question is this:
create a class RationalNumber (fractions) with the
following capabilities:
a) create a constructor that prevents a 0 denominator in a fraction, reduces
or simplifies fractions that are not in reduced form and avoids negative
denominators
b) overload the addition, substraction, multiplication and division operators
for this class
c) overload the relational and equality operators for this class

I’m working on overloading the addition operator.

I have completed a, but I am not getting anywhere on overloading. I have searched the internet for a better explanation, but I am just not grasping the concept of how to overload operators with user defined types.

Each RationalNumber has a numerator and a denominator that combine to make a fraction. I need to add them together, find the common denominator, etc.

My RationalNumber.h is thus:

// RationalNumber.h
// RationalNumber class definition
#ifndef RATIONALNUMBER_H
#define RATIONALNUMBER_H

#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

class RationalNumber
{

public:
RationalNumber( int numerator, int denominator);

void setNumerator(int numerator);
int getNumerator();

void setDenominator(int denominator);
int getDenominator();

void printRationalNumber();

RationalNumber operator+(Rationalnumber a, RationalNumber b);

private:
int numerator; //top number
int denominator; //bottom number
};

#endif

Now, just focusing on my operator+ function:

RationalNumber RationalNumber::operator+(RationalNumber a, RationalNumber b)
{

}

Visual Studio is telling me that class Rationaloperator has no member “operator+”

Any help would be appreciated.

Thanks,
Eric

UPDATE:

I now have:

RationalNumber operator+(Rationalnumber a);

and

RationalNumber RationalNumber::operator+(RationalNumber a)
{

}

I’m getting error: deceleration is incompatible…..( < error_type > a)

  • 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-26T22:59:54+00:00Added an answer on May 26, 2026 at 10:59 pm

    + is a binary operator. If you make it a member, it should only take one argument, since the calling object is the left operand.

    Also note that you don’t have to make it a member. What I usually do is implement operator+= as a member, then operator+ as a free function that utilizes operator+=. This has the advantage that either the left or the right operand can be implicitly converted. For example, if the RationalNumber class had an implicit conversion from double:

    RationalNumber r1,r2;
    r1 = r2 + 3.14; // this will work either way
    r1 = 3.14 + r2; // can't do this if operator+ is a member
    

    As for your error about incompatible declarations:

    RationalNumber operator+(Rationalnumber a);
                                     ^
                           Should be a capital N
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got this exercise working perfectly: import acm.program.*; import acm.graphics.*; import java.awt.event.*; public
I am working with Google Python class exercises where I am getting this issue
I'm working on an exercise from Accelerated C++: Write a program to count how
I have been working on a small exercise for my CIS class and am
I'm working on an exercise on the textbook Operating System Concepts 7th Edition, and
i'm working through SICP - one exercise is to implement foreach (doseq). This is
I am working on exercise 13 from learnpythonthehardway.org. I should run this code: from
I am working on an exercise in operator overloading. I've created a matrix class
I am working on this test page: http://www.problemio.com/index_new.php and you see the categories that
In solving exercise 5, I ran into a similar issue as this question .

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.