I have a class which contains pure virtual functions. I am using this class to make sure I do not forget to implement some methods in derived classes.
I have a collection of derived classes like
class B : public A
class C : public A
class D : public A
etc
How can I create a container that can hold all of these derived classes (B,C,D)? I would prefer to use a standard container such as vector. I tried creating a vector of the base class but this results in the derived classes being converted if they are pushed onto the vector leading to a compilation error of invalid new-expression of abstract class type.
My base class:
class A
{
public:
A();
virtual ~A();
virtual double GetVolume() = 0;
};
Example derived class:
class B : public A
{
public:
B(){};
virtual ~B(){};
double GetVolume(){};
};