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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:31:51+00:00 2026-05-28T01:31:51+00:00

Say, given the following smart pointer scheme: weak_ptr<Style> A -> weak_ptr<Style> B -> shared_ptr<Style>

  • 0

Say, given the following smart pointer scheme:

 weak_ptr<Style> A -> weak_ptr<Style> B -> shared_ptr<Style> C

Can you change the second weak_ptr (B) to point (observe) a new shared_ptr (C) in a way that would still make the first weak_ptr (A) see the new changed shared_ptr (C)?

Hope that makes sense. I would like to stay away from raw pointers, given the safety weak_ptr can provide in this case.

Edit:

After re-reading boost documentation I realize that weak_ptr operator= essentially just copies another weak_ptr and not actually makes it observe another weak_ptr. So you can’t have this kind of indirection without raw pointers?

Edit 2:

To expand on my problem: I have a Label and a Glyph. A Label is a container for Glyphs. A label has a shared_ptr<Style> and Glyphs have a weak_ptr to this style. My intend is to allow quick changes of a style without actually iterating over all label glyphs. So I was thinking of having another “active” style (like a style pencil) in a Label and making all glyphs point to that pencil thing. So whenever I need a style change I simply re-assign pencil to a new Style object. Can this be done with only smart pointers or I need to mix in a raw pointer somewhere?

  • 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-28T01:31:51+00:00Added an answer on May 28, 2026 at 1:31 am

    If your objects have shared_ptr to a Style and it is the same Style then between them they handle the lifetime of this Style object. Note however that they share the reference to the same object so if you modify the style, all of them will now have a pointer to the modified style.

    If you have some table of stylesheets somewhere, and this is the main container that outlives your items, then you don’t need your items to have smart-pointers unless there is a danger that they might need to keep a reference to this style and use it even after it is removed from the table or the table disappears.

    Generally, forget about the hows for the moment and think about the whats in terms of object ownership.

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

Sidebar

Related Questions

I came across this question: say given two weights 1 and 3, u can
Given the following example code: somefile = new URL(http://somefile.rar); ReadableByteChannel rbc = Channels.newChannel(somefile.openStream()); FileOutputStream
I'm trying to accomplish the following in C#/.NET 2.0: Given an IPAddress object (say,
Given say 11/13/2008 - 12/11/2008 as the value posted back in TextBox, what would
I have a requirement. Given say Test1,Test2, I have to perform a like operation.
Let's say you were given the arrival date 12/28/10 and a departure date of
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
given a string say a 19 b c d 20, how do I test
Given a small set of entities (say, 10 or fewer) to insert, delete, or
Given a Range of numbers say 1 to 10,000, Input is in random order.

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.