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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:12:35+00:00 2026-06-11T01:12:35+00:00

I have some confusion about the shared_ptr copy constructor. Please consider the following 2

  • 0

I have some confusion about the shared_ptr copy constructor. Please consider the following 2 lines:

  1. It is a “constant” reference to a shared_ptr object, that is passed to the copy constructor so that another shared_ptr object is initialized.

  2. The copy constructor is supposed to also increment a member data – “reference counter” – which is also shared among all shared_ptr objects, due to the fact that it is a reference/pointer to some integer telling each shared_ptr object how many of them are still alive.

But, if the copy constructor attempts to increment the reference counting member data, does it not “hit” the const-ness of the shared_ptr passed by reference? Or, does the copy constructor internally use the const_cast operator to temporarily remove the const-ness of the argument?

  • 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-11T01:12:36+00:00Added an answer on June 11, 2026 at 1:12 am

    The phenomenon you’re experiencing is not special to the shared pointer. Here’s a typical primeval example:

    struct Foo
    {
        int * p;
        Foo() : p(new int(1)) { }
    };
    
    void f(Foo const & x)  // <-- const...?!?
    {
        *x.p = 12;         // ...but this is fine!
    }
    

    It is true that x.p has type int * const inside f, but it is not an int const * const! In other words, you cannot change x.p, but you can change *x.p.

    This is essentially what’s going on in the shared pointer copy constructor (where *p takes the role of the reference counter).

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

Sidebar

Related Questions

I am creating a linklist class and have some confusion about reference to objects.
I have some confusion about when to use the self keyword during ivars assignment,
I still have some confusion about this thing. What I have found till now
I have some confusion about generic programming in java: If Manager is subclass of
I have some confusion about my mysql status. mysql> show status like '%key%'; +------------------------+-------+
I have some basic confusion about how transactions and msdtc work together. I have
I have some confusion about the life cycle of native code in Android aps.
I think I may have some confusion about the domain/service layer separation. In my
I have some confusion about how to use AtlasLabel. It seems Label consume a
I am trying to learn OOP in PHP, and I have some confusion about

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.