I'm having trouble when using a valarray as a class member.  I compile
with g++, and my gcc is version 3.3.5.  Here's a highly simplified example:

struct ValWrapper {
  valarray<int> item;
};

int main() {
  ValWrapper v;
  v.item=valarray<int>(-1,10);
  v.item[1]=23;    // <--- segfault here
  return 0;
}

The assignment in the penultimate line of main gives a segfault.  However,
when I do this

int main() {
  valarray<int> v(-1,10);
  v[1]=23;
  return 0;
}

all works fine.  Replacing all instances of "valarray" with "vector" above
gives an error as well, but curiously the errors are different.  I get
"Segmentation fault (core dumped)" for valarrays and "Aborted (core
dumped)" for vectors.  I believe my assignments are syntactically correct.
Any pointers?  Thanks in advance.

Meph 
_______________________________________________
Help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to