Flexo1515
Flexo1515

Reputation: 1017

c++ struct array definition

I am wondering if there is a better way to simply create a struct containing an array with a SIZE:

...
#define SIZE 100;
...

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

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

Upvotes: 0

Views: 124

Answers (1)

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143061

as long as SIZE is a compile-time constant you can simply

struct foo {
    bar bars[SIZE];
}

Upvotes: 4

Related Questions