提问人:lightxbulb 提问时间:10/17/2019 更新时间:10/17/2019 访问量:304
在构造函数中复制静态数组
Copy static array in constructor
问:
是否有编译时表达式来复制对象构造函数中的数组?默认构造函数使用什么?我想要这样的东西:
struct A
{
int arr[100];
// I want something like this:
A(const A& arg) : arr{arg.arr...} {}
// what I use at the moment (a compile time loop):
A(const A& arg)
{
static_for<0, N>([&](auto i) { arr[i] = arg.arr[i]; });
}
};
我不想使用 ,并且我在 copy ctor 中有一些调试信息,所以我不能依赖默认的。std::array
答:
评论
std::array
“ 为什么?它完全符合您的需求。<array>