[osg-submissions] osg::Object::clone

Stephan Maximilian Huber ratzfatz at digitalmind.de
Fri Jun 6 06:21:06 PDT 2008


Jean-Sébastien Guay schrieb:
> With the changes you have made, the following code will fail:
>>
>> Object* a = new Transform();
>> Transform* b = dynamic_cast<Transform*>(a->clone());
>> assert(b);
>
> Will it? Just playing Devil's advocate here, I don't care either way, 
> and I may be showing my poor C++ skills, but since the clone() method 
> is virtual, a->clone() will return a Transform* (with Valery's 
> changes), and dynamic_casting a Transform* to a Transform* will just 
> be a no-op and return the same object, so the assert will not fail...
>
> Or am I seeing this wrong?
To my knowledge, the code will fail because the c++compiler will call 
osg::Object::clone and not osg::Transform::clone because the function 
signatures differ (they return different types of objects).

cheers,
Stephan



More information about the osg-submissions mailing list