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

Paul Martz pmartz at skew-matrix.com
Thu Sep 11 14:35:47 PDT 2008

> El Jueves 11 Septiembre 2008ES 18:37:07 Paul Martz escribió:
> > > The example in the middle of page 37, above the one Cliff cited, 
> > > looks like it won't compile.  Did you really mean to 
> return *grp?  I 
> > > know it's meant to show bad programming practice but the 
> book reads 
> > > like it should compile.
> >
> > You are correct, that code is wrong. I meant to return 
> grp.get() as an 
> > example of returning a dangling pointer.
> >
> > I've added this to the errata at 
> http://www.skew-matrix.com/osgqsg/. 
> > Thanks for catching this.
> Curious. I already had "return *grp" on my hard copy.

Yes, and that's wrong. "return *grp" returns and instance of a Group, but
the function is declared to return a pointer to a Group, so it won't
compile. (The example is meant to demonstrate a common coding mistake, but
it should at least compile. :-)

The example should be changed to read "return grp.get()". This is the
"correct" way to demonstrate returning a dangling pointer (something you
should never do).

More information about the osg-users mailing list