A New Krazy Checker for Methods Returning const refs

Hans Meine hans_meine at gmx.net
Tue Apr 17 12:11:39 BST 2007


Hi!

Am Sonntag, 15. April 2007 22:56 schrieb Thomas Zander:
> > So what about returning pointers?
>
> My policy is that returnng pointers is only allowed in two cases;
> a) when transferring ownership of the object.  Factory methods come to
> mind.
I got used to auto_ptr<> for this case.  An auto_ptr makes the transfer of 
ownership explicit, which AFAICS warrants its use in an API even if the 
caller should want to immediately call release() again.

> b) when the class returning the pointer didn't have ownership anyway.
> Think manager design pattern
>
> Unfortunately it is required to have a set of rules like this to avoid
> memory leaks or worse.
..and without auto_ptr<>, you need additional docs to discriminate between 
cases a) and b).

Ciao, /  /
     /--/
    /  / ANS




More information about the kde-core-devel mailing list