I have the following code in a source file:
#include <iostream>
#include <string>
struct Foo{ std::string name; };
Foo getDefaultFoo(){
Foo f;
f.name = "test";
return f;
}
void test(Foo f = getDefaultFoo()) {
std::cout << f.name << std::endl;
}
When I compile it, it works as expected, but when I run it in the interpreter I get a segmentation violation:
root [0] .L testScript.cxx
root [1] test()
*** Break *** segmentation violation
Why is this happening? What is causing this error?
Interestingly I also get a segmentation violation when load the file (".L") and type only “test” and then press tab (which should show me the possible function signatures).
I also tried to change the code to this:
struct Foo{
std::string name;
Foo() : name("test") {}
};
void test(Foo f = Foo()){
std::cout << f.name << std::endl;
}
but it keeps crashing with a segmentation violation…
I am using root 5.43 and even if I could compile it I would like to know why the interpreter doesnt swallow it, because the code is part of some bigger code that I cannot compile (unless I change lots of code).