Q:

Indirect multi-level smart pointers

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?

A:

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.

