我有一组具有以下结构的类:
class U
{
public:
explicit U(int) { ... }
U() {...}
Init(int) {...}
};
我需要能够将这些类中的一个或多个组成一个类 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 解决方案。