C++ feature of the day: shared_ptr's aliasing constructor! Given a shared_ptr to an object, the aliasing constructor creates a new shared_ptr to a member of the object while sharing the same ref count: shared_ptr<A> a = make_shared<A>(); shared_ptr<B> b(a, &a->member);
-
-
I guess most of the time, when doing sp->x, you only want a reference, not a full blown shared_ptr. Creating a shared_ptr involves atomics to manage the ref count, doing that for every member access feels a bit overkill. I prefer the manual way, even if it;s error prone!
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.