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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:01:00+00:00 2026-06-09T09:01:00+00:00

This is the error that I get Linker error undefined reference to RationalNumber::RationalNumber(int, int)

  • 0

This is the error that I get
Linker error undefined reference to RationalNumber::RationalNumber(int, int)

I tried with Visual studio and the error says, cannot find the specified file rationalnumber.exe.

The Header file

#ifndef __Assignment_2Q1__RationalNumber__
#define __Assignment_2Q1__RationalNumber__

#include <iostream>
using namespace std;


class RationalNumber{





public:
    RationalNumber(int=0, int=1); // prevent 0 at denominator! and reduce fraction and avoid -ive


    friend RationalNumber operator+(const RationalNumber &r1,const RationalNumber &r2); // need & reference
    friend RationalNumber operator-(const RationalNumber &r1,const RationalNumber &r2);
    friend RationalNumber operator*(const RationalNumber &r1,const RationalNumber &r2);
    friend RationalNumber operator/(const RationalNumber &r1,const RationalNumber &r2);

    friend bool operator==(const RationalNumber &n1,const RationalNumber &n2);
    friend bool operator!=(const RationalNumber &n1,const RationalNumber &n2);

    friend bool operator>(const RationalNumber &n1,const RationalNumber &n2);
    friend bool operator<=(const RationalNumber &n1,const RationalNumber &n2);

    friend bool operator<(const RationalNumber &n1,const RationalNumber &n2);
    friend bool operator>=(const RationalNumber &n1,const RationalNumber &n2);

    void print();


private:

    int denominator;
    int numerator;





};






#endif /* defined(__Assignment_2Q1__RationalNumber__) */

The cpp file

#include <iostream>
#include "RationalNumber.h"


using namespace std;

RationalNumber(int n, int d)
{
    if (d!=0&&d>0) {
        if (d>=2||d<=-2) {
            float fraction1;
            float fraction2;
            fraction1= n/d;
            fraction2 = static_cast<float>(n)/d;

                if (fraction1==fraction2) {  // OR just simply 4/2 = 2 so n=2 , d=1!!! 
                numerator=fraction1;
                denominator=1;
                cout<<"You have entered a reductible fraction which reduces to! \n "<<numerator<<" / "<<denominator<<endl;
            }
                else{
                numerator=n;
                denominator=d;
                cout<<"You have enterd an irreductible fraction! "<<numerator<<" / "<<denominator<<endl;
            }
        }
        else
        {
            numerator=n;
            denominator=d;
            cout<<"The rational number is "<<numerator<<" / "<<denominator<<endl;
        }

    }
    else
        cout<<"The denominator cannot be 0 or a Negative number!"<<endl; // maybe add a set fct here

}



 RationalNumber operator+(const RationalNumber& r1,const RationalNumber& r2)
{
    return RationalNumber((r1.numerator+r2.denominator)/(r1.denominator+r2.denominator));

}
 RationalNumber operator-(const RationalNumber &r1,const RationalNumber &r2)
{
    return RationalNumber((r1.numerator-r2.denominator)/(r1.denominator-r2.denominator));

}

 RationalNumber operator*(const RationalNumber &r1,const RationalNumber &r2)
{
    return RationalNumber((r1.numerator*r2.denominator)/(r1.denominator*r2.denominator));
}

 RationalNumber operator/(const RationalNumber &r1,const RationalNumber &r2)
{
    return RationalNumber((r1.numerator/r2.denominator)/(r1.denominator/r2.denominator));

}


bool operator==(const RationalNumber &n1,const RationalNumber &n2)
{
    return ((n1.numerator/n1.denominator)==(n2.numerator/n2.denominator));
}

 bool operator!=(const RationalNumber &n1,const RationalNumber &n2)
{
    return ((n1.numerator/n1.denominator)!=(n2.numerator/n2.denominator));

}


 bool operator>(const RationalNumber &n1,const RationalNumber &n2)
{
    return ((n1.numerator/n1.denominator)>(n2.numerator/n2.denominator));

}

 bool operator<=(const RationalNumber &n1,const RationalNumber &n2)
{
    return ((n1.numerator/n1.denominator)<=(n2.numerator/n2.denominator));

}



 bool operator<(const RationalNumber &n1,const RationalNumber &n2)
{
    return ((n1.numerator/n1.denominator)<(n2.numerator/n2.denominator));

}

 bool operator>=(const RationalNumber &n1,const RationalNumber &n2)
{
    return ((n1.numerator/n1.denominator)>=(n2.numerator/n2.denominator));

}

void RationalNumber::print()
{
    cout<<numerator<<endl;
    cout<<denominator<<endl;
}

The main

#include <iostream>
#include "RationalNumber.h"

using namespace std;

int main()

    {

        RationalNumber object1(34, 73);

        RationalNumber object2(5, 1);

        RationalNumber object3(50, 25);

        RationalNumber object4(87, 21);

        RationalNumber object5(32, 0);

        RationalNumber object6(32, -3);

        RationalNumber object7(-32, 2);

        RationalNumber object;

        object = (object1 + object2);

        object.print();

        return 0;
    }
  • 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-06-09T09:01:02+00:00Added an answer on June 9, 2026 at 9:01 am

    Change

    RationalNumber(int n, int d)
    

    in your .cpp to

    RationalNumber::RationalNumber(int n, int d)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see that many people get this error, but their situations all appear a
Im getting this linker error that won't let me compile. It only happens on
Ey guys, I have been referencing this project, but I get this linker error:
I have this error that is keeping me from moving forward. I basically have
How can I resolved this error that I see in Gradle after upgrading to
How to fix this error that happens on Debian Linux using ssl commands with
This is the error that is thrown by our automated build suite on Windows
How to change my query so that this error doesn't happen: XML data type
This is probably a dum error that can be fixed in seconds but have
I am getting this error on a js function that sends an ajax request

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.