|
Boost Users : |
Subject: Re: [Boost-users] [shared pointer] - question about different types pointing to the same object
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-06-06 19:46:54
On Sat, Jun 6, 2009 at 4:12 PM, Robert Ramey <ramey_at_[hidden]> wrote:
> So how could I verify whether an arbitrary pb1 and pb2 point to the
> same object or not?
If you want to check whether two shared_ptr objects p and q share
ownership (that is, manage the same object), you can use:
!(p<q) && !(q<p)
However, you're probably asking with serialization in mind. I don't
think serialization can support the most general shared_ptr use cases,
since it supports aliasing: a shared_ptr<int> might point to an int
within a larger object of user-defined type T. Obviously, when such
shared_ptr is serialized what you want is to serialize the T, so you
need some sort of cast-like operation to get to the T address, knowing
the address of the int. Obviously this is not possible in general.
(My last blog post might also be helpful in understanding shared_ptr better.)
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net