I found out in C++ we can't have vectors of abstract classes. It needs to be a vector of pointers to it. As a workaround I've simply converted the abstract class into a fake abstract class which throws an exception if I try to directly use the method that's supposed to be overridden by a subclass.
Edit: As noted by commenters the workaround wouldn't work, so I converted it to a vector of pointers. After learning about std::unique_ptr
instead of raw pointers it was not as much of a hassle as I thought. Only gotcha moment was for (std::unique_ptr<AbstractThingy>& abstractThingy : ABSTRACT_THINGIES)
, you need the ampersand there to prevent it from making copies which would throw another compile error. Also, when instantiating the object via std::make_unique
it should be std::make_unique<ChildClassOfAbstractThingy>
rather than std::make_unique<AbstractThingy>