If I have a base class, with only virtual methods and 2 derived classes from the base class, with those virtual methods implemented.
How do I:
// ca
If your BaseClass contains pure virtual methods, this will fail to compile :
BaseClass* base = new BaseClass[2];
If it doesn't, you are going to get memory leak.
In c++, this is done by using std::vector or std::array, with some kind of smart pointer. For example :
std::vector< std::shared_ptr< BaseClass > > arr( 2 );
arr[0].reset( new FirstDerivedClass() );
arr[1].reset( new SecondDerivedClass() );