c ++ struct array definition

时间:2012-11-03 22:08:16

标签: c++ arrays struct

我想知道是否有更好的方法来简单地创建一个包含SIZE数组的结构:

...
#define SIZE 100;
...

struct foo {
    foo();
    bar * bars;
}

foo::foo() {
bars = new bar[SIZE];
}

1 个答案:

答案 0 :(得分:4)

只要SIZE是编译时常量,您就可以

struct foo {
    bar bars[SIZE];
}