1

In C++, I have two functions:

do_work(args, std::valarray<double> arr=std::valarray<double>(0.0, 1)) {
  very_complicated_things
}

wrapper(args, std::valarray<double> arr=std::valarray<double>(0.0, 1)) {
  do_work(args, arr);
}

Calling do_work(args) and calling wrapper(args) gives different results. The former works fine; the latter crashes somewhere in the do_work function and I have no idea why (the code is quite complicated). Why is this the case? If I omit the "arr" argument in the function call inside wrapper:

wrapper(args, std::valarray<double> arr=std::valarray<double>(0.0, 1)) {
  do_work(args);
}

then wrapper(args) works fine! Does anyone have an idea what's happening? I don't know where to start looking.

ideasrule
  • 210
  • 1
  • 7

0 Answers0