我有一组具有以下结构类:如何从类型列表继承,然后在继承成员列表中调用成员?
class U
{
public:
explicit U(int) { ... }
U() {...}
Init(int) {...}
};
我需要能够撰写1以上这些类为类X.伪代码:
template<class TypeSequence>
class X that derives publicly from all the classes in TypeSequence
{
X(int): all bases are initialized with the integer passed
{}
//if the above constructor is impossible, then the following will do as well:
X(int)
{
Call Init on all bases and pass the given int to them.
}
};
我想我需要很多mpl,但我并不擅长。我想要做什么?代码示例会很棒。
我的错误:忘了提及我不能使用C++ 11功能。我正在寻找MPL解决方案。
+1问得好。你听说过mixin的方式吗?也许,它可以适用于此,或它的变体? – Nawaz
我之前用[Boost.MPL](http://www.boost.org/libs/mpl/)完成了这个操作,但我没有代码,并且没有时间写一个现在完整回答。如果到那时还没有人回答,我今晚会重新回顾一下。作为一个提示,我记得做了一个特殊的mixin,它将两个'boost :: mpl :: vector <>'迭代器作为模板参数。 – ildjarn
U与TypeSequence有什么关系? –