class element
{
public:
element();
virtual void foo() = 0;
};
class bar : public element
{
public:
bar();
void foo() override
{
// Stuff
}
};
class baz : public element
{
public:
bar();
void foo() override
{
// Stuff
}
};
I want to have instances of bar and instance of baz to be stored in the same vector or list.
vector<element> elements;
bar a = bar();
baz b = baz();
elements.push_back(a);
elements.push_back(b);
I know that the code above wont work but something with this kind of structure is what I am looking for.
I read somewhere that you can store a vector of unique_ptr< element>
but I can't figure out how to turn instances of bar or baz into unique pointers of element.
Apologies if this is a duplicate, I tried looking for a solution but I couldn't find anything.