[osg-submissions] osg::Object::clone
Daniel Trstenjak
Daniel.Trstenjak at science-computing.de
Fri Jun 6 06:38:37 PDT 2008
Hi Valery,
> I suggest to you to override type of returning value in realizations of
> functions osg::Object::clone and osg::Object::cloneType in derived
> classes. In this case one will be able to write simply "osg::Transform*
> sTrans = sExistentTrans->clone();" instead of "osg::Transform* sTrans =
> dynamic_cast<osg::Transform*>(sExistentTrans->clone());".
It's not a good idea. The return value of the 'clone' method is
different (gcc 4.1.1) in dependency of the type of the pointer holding
the object.
class A {
public:
virtual A* clone() const { return new A(); }
};
class B: public A {
public:
virtual B* clone() const { return new B(); }
};
int main() {
B* b1 = new B();
B* b2 = b1->clone();
A* a = new B();
B* b3 = a->clone();
}
Greetings,
Daniel
--
Daniel Trstenjak Tel. +49 (0)7071-9457-264
science + computing ag FAX +49 (0)7071-9457-511
Hagellocher Weg 73 mailto: Daniel.Trstenjak at science-computing.de
D-72070 Tübingen WWW : http://www.science-computing.de/
--
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Florian Geyer,
Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Prof. Dr. Hanns Ruder
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196
More information about the osg-submissions
mailing list