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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:36:12+00:00 2026-05-16T18:36:12+00:00

I am facing a problem with the code below which is run on Visual Studio 2008.

  • 0

I am facing a problem with the code below which is run on Visual Studio 2008. How do I write the function definition for operator + when you have a statement to be overloaded as follows?

class Distance
{
    private:
        int feet,inches;
};

main......

Distance Obj, Obj1(2, 2);

Obj = 3 + Obj1; // This line here

Obj1+3 is easy, but how does this one compiler know that it has to do overloading?

Suppose I have to add the value 3 to the data member feet of Obj1.

  • 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-16T18:36:13+00:00Added an answer on May 16, 2026 at 6:36 pm

    Generally an operator of that form would be declared as:

    Distance operator+(int lhs, const Distance& rhs) {
      // Assuming the int value represents feet
      return Distance(rhs.feet + lhs, rhs.inches);
    }
    

    You’d probably also want to define the symmetric:

    Distance operator+(const Distance& lhs, int rhs) {
      // Assuming the int value represents feet
      return Distance(lhs.feet + rhs, lhs.inches);
    }
    

    Also, I suggest you heed the advice of James McNellis–your job will be simplified if you just have one member representing lengths in a single unit.

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

Sidebar

Related Questions

I am facing problem with hibernate annotations.For the code shown below I have a
iam facing problem in passing array to view. this is my controller code.. function
hi im new to jquery and im facing these problem i have these code
Brand new to android and facing a weird problem.Check out the code below FirstActivity.java:
I'm facing a problem in C++ for which I currently don't have an elegant
In my c# appliaction am facing problem in below code,for deleting items from database,
Iam facing problem in understanding and converting a matlab code into opencv. I want
I am facing a problem with EF Code First with TPH. I am getting
i am using mvc 3 code first. facing problem while passing data form SecurityAttribute
i am facing the problem tapping on the table view my code was not

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.