For the sake of clarity, I\'ve removed things like the constructor & destructor etc from the below where they don\'t add anything to the question. I have a base class t
You've got your ellipsis in the wrong place. Try:
template<template<typename...> class... Args>
^^^ here
However, you don't actually want template template parameters; since DerivedSystem1<1>
is a type, not a template, you just want ordinary typename parameters:
template<typename... Args>
class ContainerClass {
For the actual container, you can't use vector<PeripheralSystem>
as that is homogeneous and will slice the derived types down to PeripheralSystem
. If you add a virtual destructor to PeripheralSystem
you can use vector<unique_ptr<PeripheralSystem>>
:
template<typename... Args>
class ContainerClass {
public:
ContainerClass() : container{std::make_unique<Args>()...} {}
std::vector<std::unique_ptr<PeripheralSystem>> container;
};
However, tuple
would work just as well and result in fewer allocations:
template<typename... Args>
class ContainerClass {
public:
ContainerClass() : container{Args{}...} {}
std::tuple<Args...> container;
};