0

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];
}
4
  • 2
    Sure: struct foo { foo(); std::array<bar, SIZE> bars; }; Commented Nov 3, 2012 at 22:09
  • 1
    Well, SIZE is a compile time constant, so you do not need a dynamically alocated array. You can have a bar bars[SIZE] data member. Commented Nov 3, 2012 at 22:10
  • 1
    @chris, you have unbalanced <> ;-) Commented Nov 3, 2012 at 22:11
  • @MichaelKrelin-hacker, Oops. Thanks for noticing. Commented Nov 3, 2012 at 22:11

1 Answer 1

4

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

struct foo {
    bar bars[SIZE];
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.