[osg-users] Returning ref_ptr<> vs. ref_ptr<>::get()

Paul Martz pmartz at skew-matrix.com
Wed Sep 10 14:35:15 PDT 2008

> What I don't understand is 
> why he doesn't just return "grp" and let it call the copy ctor.

In the example you cited, I could've done as you suggest. But as you and
Robert already discussed, this wouldn't work if the return type were a
ref_ptr to a base class of Group.

I figure there are two types of programmers: those who know C++ and can spin
up on things like ref_ptr in a matter if a few minutes just by glancing at
the code, and those who aren't so experienced and need some hand holding. To
address the needs of the latter group, the section on ref_ptr could have
been an entire chapter unto itself. To keep the book short and affordable, I
decided to give them a set of short but "safe" instructions that would keep
them out of trouble when using ref_ptrs. Exploring all of ref_ptr's ins and
outs is left as an exercise to the reader. (There are, of course, multiple
ways to return ref_ptr memory from a function. If I update the book, I'll
consider recommending release(), for example.)

Thanks for reading the book.

Paul Martz
Skew Matrix Software LLC
+1 303 859 9466

More information about the osg-users mailing list