Hi Peter, I think you question is really about overriding virtual methods in C++, but I'm not sure.
If call geometry->clone() and the geometry object is an instance of PiFaceGeometry then the clone method called will be PiFaceGeometry::clone() even if the geometry pointer you have is of the parent class osg::Geometry. i.e. PiFaceGeometry* myFaceGeometry = new PiFaceGeometry; Geometry* geometry = myFaceGeometry; geometry->clone(); // will call PiFaceGeometry::clone(). Robert. On 30 November 2011 12:18, Peter Bako <bakopet...@gmail.com> wrote: > Hello guys! > I have run a search over the topics, but I didn't find an answer for my > question, so here it is: > > I have my own derived class called PiFaceGeometry, which is derived from > osg::Geometry class, I use this to work with faces of solids - so I have the > type of face - cylinder, plane, and other which I store within this class and > also some other properties. > I have a different class called SolidComponent, which is derived from > osg::MatrixTransform and represent machinery workpieces and tools. > > The problem is that sometimes I need to clone the SolidComponent (which > contains Geode as child with PiFaceGeometries, and can also contain other > SolidComponents as children). I think, I need a deep copy, because sometimes > I have to change the color of triangles, or am I wrong? The question is, how > should I reimplement the clone() function? I looked also into the osg source > code but I didn't understand the way, how to do this. > > How can I force the program to call PiFaceGeometry::clone() if this is only a > child of object, on which I called clone()? > I am sorry If this question is silly, I am not a good C++ programmer and I > hate C++ :-P. > > Thank you for your responses! > > Cheers, > Peter > Code: > > class PiFaceGeometry: public osg::Geometry { > public: > osg::ref_ptr<osg::IntArray> edges; > PiSurfaceType surfType; > void changeFaceColor(osg::Vec4 color){...}; > PiFaceGeometry * clone(const osg::CopyOp ©op ){ > //how can I reuse Geometry::Clone(), if it returns a Geometry but I need > PiFaceGeometry? > } > }; > > > > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=44132#44132 > > > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org