Shape Derived Classes Lack Co-Variant Return Type for Clone()
Jmeyer1292 opened this issue · comments
Jonathan Meyer commented
C++ has covariant return types. They are useful for things. They are especially useful for implementing clone()
functions polymorphically. See this page.
So for instance:
class Mesh : public Shape
{
//...
virtual Shape* clone() const;
// ...
};
should be
class Mesh : public Shape
{
//...
virtual Mesh* clone() const;
// ...
};
I was attempting to load many, large models using this library. I wanted to cache the shapes::Mesh*
pointers using their URI name. Unfortunately even though I know I have a Mesh, I can't clone it to a mesh because the function returns the base class. This currently requires an unneeded dynamic_cast to fix.
Michael Görner commented
Sounds good. Could you provide a patch please?
Robert Haschke commented
Fixed in #102.