Hugh

Hugh

  • NA
  • 3
  • 0

populating an array of structs at compile time?

Mar 6 2009 5:37 PM
I'm a little embarrassed to ask this one, since it seems so fundamental, but here goes anyway:

I'm trying to create an array of structs which I'll populate at compile-time.  So I've got a struct

struct S {
  string str;
  int idx;
  double wgt;
};

which I want to populate something like this:

S [] s = {
  { "name", 0, 1.24 },
  { "foo", 3, 3.14 },
  ...
  { "", 0.0, 0.0 }
};


I've tried the above and a variety of permutations, but can't figure out how to get the compiler to accept it.  I can call the struct a class, but that doesn't seem to make much difference.  It's a big list, and this kind of problem is not unusual in coding, so there must be a way!

Thanks for any help,
Hugh


Answers (2)