0
我想知道是否有更好的方法来简单地创建一个包含一个大小的数组一个结构:C++结构数组定义
...
#define SIZE 100;
...
struct foo {
foo();
bar * bars;
}
foo::foo() {
bars = new bar[SIZE];
}
我想知道是否有更好的方法来简单地创建一个包含一个大小的数组一个结构:C++结构数组定义
...
#define SIZE 100;
...
struct foo {
foo();
bar * bars;
}
foo::foo() {
bars = new bar[SIZE];
}
只要SIZE
是一个编译时间常数,你可以简单地
struct foo {
bar bars[SIZE];
}
当然:'struct foo {foo(); std :: array bars; };' –
chris
那么,'SIZE'是一个编译时间常量,所以你不需要一个动态分配的数组。你可以有一个'bar bars [SIZE]'数据成员。 – juanchopanza
@chris,你有不平衡的'<>';-) –