moveit / geometric_shapes

Representation of geometric shapes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shape Derived Classes Lack Co-Variant Return Type for Clone()

Jmeyer1292 opened this issue · comments

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.

Fixed in #102.