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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:44:56+00:00 2026-06-15T07:44:56+00:00

I have a question that is similar to the question that was asked here:

  • 0

I have a question that is similar to the question that was asked here: How does "this" cascading work?

Suppose I have the following code:

#include <iostream>
using namespace std;

class Time
  {
  public:
     Time( int = 0, int = 0, int = 0 );
     Time setHour( int );
     Time setMinute( int );
     void print( void );

  private:
     int hour;
     int minute;
  };

  Time::Time(int hr, int mn, int sc)
  {
     hour = hr;
     minute = mn;
  }

  void Time::print( void )
  {
     cout << "hour = " << hour << endl;
     cout << "minute = " << minute << endl;
  }

  Time Time::setHour( int h )
  {
     hour = ( h >= 0 && h < 24 ) ? h : 0;
     return *this;
  }


  Time Time::setMinute( int m )
  {
     minute = ( m >= 0 && m < 60 ) ? m : 0;
     return *this;
  }

int main()
{
   cout << "Hello, world!" << endl;
   Time t;
   t.setHour( 10 ).setMinute( 25 );
   t.print();
}

Then, it is clear that the function setMinute( 25 ) is not running on the Time object t. Note that the functions setHour and setMinute do not return references to Time objects.

What is happening after t.setHour( 10 ) executes? Does the function setHour somehow return a “copy” of the object t, and setMinute( 25 ) is running on the copy? I have compiled the program with -Wall and no errors or warnings are returned.

Thanks for your assistance.

  • 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-15T07:44:57+00:00Added an answer on June 15, 2026 at 7:44 am

    Your analysis seems correct. This expression

    t.setHour( 10 )
    

    returns a temporary Time object. You then call setMinute(25) on that temporary. This in turn returns another temporary Time object, which is not assigned to anything. So setHour() acts on the t instance, but setMinute() acts on a temporary, which disappears at the end of this line

    t.setHour( 10 ).setMinute( 25 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess this question that would have already been asked here. I searched but
I realize that similar questions have been asked about this before here on SO,
I realize that there was a similar question asked here , but this is
Similar to this question I have a custom subclass of UITableViewCell that has a
Similar to this question: link However I have already mastered that. My problem is
I know that this is a repeated question. I have found very similar questions
I have another question. Quite similar to the other that i already asked (and
I believe this question is slightly different than similar ones asked on here before
I have asked a similar question previously but it was never resolved so here
Similar question have been asked here but none fits to my need. I made

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.