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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:37:17+00:00 2026-06-05T16:37:17+00:00

This is a follow up question from Calling constructor in return statement . This

  • 0

This is a follow up question from Calling constructor in return statement.

This a operator overload fun in a class.

const Integer operator+(const Integer& IntObject)
{
    cout << "Data : " << this->data << endl;
    return Integer(this->data + IntObject.data); 
}

What is the relevance of const in the return type for such functions?

int main()
{
    Integer A(1); //Create 2 object of class Integer

    Integer B(2);

    const Integer C = A + B;  //This will work

    Integer D = A + B;        //This will also work

    fun(A + B);               //Will work
}

void fun(Integer F) {}

This is a case temporaries are not created during return step due to NRVO. The object to be returned is directly constructed on the callee’s address.

  • 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-05T16:37:20+00:00Added an answer on June 5, 2026 at 4:37 pm

    There is no relevance in your code snippet, because you are making a copy of the returned value.

    In general, it is difficult to find good reasons to return a const value. I can only see it having an effect in this type of expression, attempting to call a non-const method on a const temporary:

    (someObject.someMethodReturningConstValue()).someNonConstMethod(); // error, calls non const method on const temporary
    

    so you should only use it if you want to disallow calling non-const methods on temporaries. On the other hand, it kills move-semantics in C++11 so is discouraged.

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

Sidebar

Related Questions

(This question is a follow up from Safari Scrollbars & SVG - the workaround
This is a follow-on question from the one I asked here . Can constraints
This is a follow up from this question, Lock Cells after Data Entry .
This is a follow up from a question of mine that was just answered
This is a follow-on from this question, in which I was trying to suppress
This is a follow on from my previous question although this is about something
This question is a follow on from this one ... I am binding to
This is a follow up question from Problem with array assignment I now have
This is a follow up question from Grammar: difference between a top down and
Note that this is a follow-up question from my previous one: How to memorize

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.