< Previous by Date Date Index Next by Date >
  Thread Index  

[reSIProcate] Re: Passing shared pointers


From: david Butcher <davidlbutcher@xxxxxxxxx >
To: resiprocate-devel@xxxxxxxxxxxxxxxxxxx
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