Template template parameters with variadic templates

前端 未结 1 668
青春惊慌失措
青春惊慌失措 2021-01-06 23:48

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

1条回答
  •  盖世英雄少女心
    2021-01-07 00:13

    You've got your ellipsis in the wrong place. Try:

    template 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
    class ContainerClass {
    

    For the actual container, you can't use vector 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>:

    template
    class ContainerClass {
      public:
        ContainerClass() : container{std::make_unique()...} {}
        std::vector> container;
    };
    

    However, tuple would work just as well and result in fewer allocations:

    template
    class ContainerClass {
      public:
        ContainerClass() : container{Args{}...} {}
        std::tuple container;
    };
    

    0 讨论(0)
提交回复
热议问题