5
如果将以下代码中的X
转换为使用C++ 11变量模板,并且应该支持任意数量的模板参数,那该怎么办?将变异模板链接在一起
template<int OFFSET>
struct A { enum O { offset = OFFSET }; enum S { size = 2 }; };
template<int OFFSET>
struct B { enum O { offset = OFFSET }; enum S { size = 4 }; };
template<int OFFSET>
struct C { enum O { offset = OFFSET }; enum S { size = 10 }; };
template < template <int> class B0,
template <int> class B1,
template <int> class B2 >
struct X : public B0<1>,
B1<B0<1>::size * B0<1>::offset >,
B2< B1<B0<1>::size * B0<1>::offset >::size *
B1<B0<1>::size * B0<1>::offset >::offset >
{ };
int main(int argc, const char *argv[])
{
X<A, B, C> x;
return 0;
}
有一些细节丢失,你传递'参数数量...''到,但X_helper',预计第一个参数是'int'。 – SirGuy 2016-07-05 20:13:18
你是绝对正确的,谢谢:) – filmor 2016-07-06 10:09:14