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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:27:26+00:00 2026-06-02T09:27:26+00:00

Does the operation on this pointer calls the constructor ? I have a constructor

  • 0

Does the operation on “this” pointer calls the constructor ?

I have a constructor defined as follows

    Cents(int cents)
    {
            cout<<"in cents constructor\n";
            m_cents = cents;
    }

    friend Cents operator + (const Cents &c1, const Cents &c2)
    {           
            return Cents(c1.m_cents + c2.m_cents);
    }

    Cents operator ++ (int)
    {
            cout<<"In c++ function\n";
            Cents c(m_cents);
            *this = *this + 1 ;
            return c;
    }

in main function I have sth like…

    Cents c;
    cout<<"Before post incrementing\n";
    c++; //This part is calling the constructor thrice 

Now If I am doing some operation like *this = *this + 1.
It calls this constructor twice.

What exactly is going on here. Does *this creates a temp object and assigns the value to the original object?

  • 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-02T09:27:28+00:00Added an answer on June 2, 2026 at 9:27 am

    No, dereferencing a pointer doesn’t create any new object.

    Hovever, if you have operator+ defined only for instances of your class, there will be a new instance constructed from 1, because the constructor Cents(int cents) isn’t marked as explicit.

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

Sidebar

Related Questions

Why does this work well: cout << foo; While this doesn't? (&cout)->operator<<(foo); It works
Does using this pointer adds another operation to the program at runtime? Just to
this code is the base of lexer , and it does the basic operation
What does the following mean? Class.Function(variable := 1 + 1) What is this operator
I have a script that does a whole bunch of fread and fseek calls
I've got a small program that opens a file and does some operation on
I was always wondering how does the login operation performs so quickly when I'm
In Python, and in general - does a close() operation on a file object
Does the delete shelveset operation reclaim space used by the changeset in tfs database?
Does some basic list operation in Haskell(e.g. ghc) are optimized equivalently to their imperative

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.