I am encountering a segmentation fault and I don't understand how this is possible. Within a class, I have two methods like this:
Declaration s in header:
int do_something() const;
void do_something_helper(const T &a, const T &b, const double new_param) const;
In myclass.cpp file:
int MyClass::do_something() const {
double new_param = {calculation}
...
std::cout << "Value of new param is: " << new_param << '\n';
do_something_helper(a,b,c,new_param);
...
return something;
}
void MyClass::do_something_helper(const T &a, const T &b, const double new_param) {
const double another_value = {calculation};
if(new_param < another_value)
...
}
The output statement in do_something works fine. A value is output without incident. If I remove any use of new_param in do_something_helper, there is no incident. It's only when I attempt to compare, output, or do anything with it that there is an instant segfault.
How is this even possible? I don't understand how I can have a segmentation fault on a primitive that has been passed by value. Any ideas?
new_param is a very recent addition. No runtime errors without it. If I take it out, it all goes smoothly. (But obviously I need it to do something new.)
Even more mysterious is that if I hardcode a value, like
do_something_helper(a,b,c,5.0);
I still get the seg fault.