Hi, I want to make a class with a vector inside that storages shapes for me (e.g. a rectangle, circle). I know that sf::RectangleShape's and sf::CircleShape's base class is sf::Shape, so I made a class like that (includes are irrelevant here, they are fine):
//header file
class ObjectStorage
{
private:
std::vector <std::shared_ptr<sf::Shape>>sequence;
public:
ObjectStorage();
void add(std::shared_ptr<sf::Shape> const &ob);
void show();
};
//cpp file
void ObjectStorage::add(std::shared_ptr<sf::Shape> const &ob)
{
sequence.push_back(ob);
}
As you can see whenever I want to call the method add with a rectangle or circle shape called test1 I do it like that (objectstorage is a pointer that is initialized with the ObjectStorage constructor, no problems with it as well):
objectstorage->add(test1);
Although it gives me this compiler error "no suitable user-defined conversion from "sf::RectangleShape" to "const std::shared_ptr<sf::Shape>" exists".
How can I store rectangle, convex and circle shapes in a single vector?