[osg-users] META_object macro returning osg::Object* for cloneType and clone

Robert Osfield robert.osfield at gmail.com
Mon Nov 27 00:17:09 PST 2017

HI Hartwig,

I attempted at having different return types with Object::clone() in
different subclasses many years ago but different compilers would
accept or not accept this usage, it simple wasn't portable enough to
roll out.

If you know the type and want to clone without doing the extra C++
legwork you can use the osg::clone(..) method i.e.

   osg::Texture2D* orig_texture; = ....
   osg::ref_ptr<osg::Texture2D> new_texture = osg::clone(orig_texture);

This will do the required dynamic for you.

If you are worried about the cost of the dynamic cast then you could
just explicitly call the copy constructor:

   osg::ref_ptr<osg::Texture2D> new_texture = new osg::Texture2D(*orig_texture);


More information about the osg-users mailing list