c ++初始化列表和可变参数模板
我想创建一个数组:
template < typename T, typename ... A > struct a {
T x [1 + sizeof... (A)];
a () = default;
a (T && t, A && ... y) : x { t, y... } {}
};
int main () {
a < int, int > p { 1, 1 }; // ok
a < a < int, int >, a < int, int > > q { { 1, 1 }, { 3, 3 } }; // error: bad array initializer
}
为什么不编译? (用g ++ 4.6测试)
没有找到相关结果
已邀请:
1 个回复
玖料萄
可用于代替
为构造函数提供参数。因此你的代码应该没问题:
所以整件事应该没问题。