so I have a Top class, let say:
//Top.h
#pragma once
#include
using std::string;
class Top
{
protected:
string name;
public:
Use the pointers and arrays of C++:
typedef std::array,3> Tops;
Tops tops =
{{
new MiddleA( "Kuku", 1337 ),
new MiddleB( "Hoi", 42.0 ),
new MiddleC()
}};
Only thing you have to have virtual destructor on your Top. Without virtual destructor you may only use shared_ptr, others will result with undefined behavior when objects are destroyed.