[C++-sig] how to handle bare references with a shared_ptr HeldType
Hans Meine
hans_meine at gmx.net
Thu Sep 22 00:34:47 CEST 2005
On Thursday 22 September 2005 00:20, Gregory Price wrote:
> class A {
> // ... lots of stuff ...
> };
>
> class B {
> shared_ptr<A> a;
> public:
> A& getA() { return *a; };
> };
> """
>
> I'm exposing A with a HeldType of shared_ptr<A>.
>
> [...]
> I could use copy_non_const_reference to make a
> new copy of the A instance. That'd be safe,
> but A instances are big and I'd rather not copy them.
Hmm. What about return_internal_reference (which I am using a lot)?
AFAICS, the C++ A object will not be deleted as long as B is not deleted,
because of the shared ptr. OTOH, during the lifetime of the A python
wrapper, B will not get deleted because of the custodian-ward relationship
initialized via return_internal_reference. Does that make sense?
--
Ciao, / / .o.
/--/ ..o
/ / ANS ooo
More information about the Cplusplus-sig
mailing list