[reSIProcate] Re: Passing shared pointers
Alan Stokes
alan at alanstokes.org.uk
Wed Sep 14 04:18:19 CDT 2005
>
> From: david Butcher <davidlbutcher at gmail.com>
> To: resiprocate-devel at list.sipfoundry.org
> Subject: Re: [reSIProcate] Minor point: passing shared pointers
> SharedPtr is not a normal type -- it has special casting behavior.
> Passing it by reference defeats its casting properties.
>
> For example, if B is derived from A, a SharedPtr<B> can be passed by value
> to a formal parameter of SharedPtr<A>.
> If you pass it by reference, it will not match.
But if you pass it by const reference, it will match. (A temporary is
created by converting the SharedPtr<B> to a SharedPtr<A> and then a
reference to this temporary is passed.)
Both by value and by const reference preserve this useful behaviour. By
const reference may be preferred for efficiency reasons (although there's
very little in it).
- Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20050914/be49e5d8/attachment.htm>
More information about the resiprocate-devel
mailing list