Variadic templates and multiple inheritance in c++11

烂漫一生 提交于 2019-12-05 10:59:01

You could try recursive variadic templates, taking 2 arguments at a time to add a derivation from fooBase.

It could be something like:

template<typename A, typename B>
class fooBase
{
public:
    fooBase(){};
    ~fooBase(){};
};

template<typename A, typename B, typename ... C>
class foo: public fooBase<A, B>, public foo<C ...> {
};

// termination version by partial specialization
template<typename A, typename B>
class foo<A, B>: public fooBase<A, B> {
};

You can then declare:

foo<uint8_t, float, uint16_t, bool, uint32_t, int> bar;

and bar will be a subobject of fooBase<uint8_t, float>, fooBase<uint16_t, bool> and fooBase<uint32_t, int>

Jojje

Change foo to someting similar to this:

template<typename... Interfaces>
class foo : public Interfaces... {
  public:
    foo(Interfaces... ifaces) : Interfaces(ifaces)... {}

  };
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!