Hey folks,
please have a look at this simple class:
Code:
#include <initializer_list>
#include <string>
class test {
public:
test(std::string value, bool flag=false)
{
}
test(std::initializer_list<std::string> values, bool flag=false)
{
}
};
Now, when testing this in I get quite strange results:
Code:
int main() // compiles fine
{
test first{"abc"};
}
Code:
int main() // throws a `std::lenght_error' with `what(): basic_string::_S_create'
{ test second{{"abc", "def"}};
}
Code:
int main() // fine again
{
test first{"abc"};
test second{{"abc", "def"}};
}
I really don't understand how the construction of the instance `first' can resolve whatever problem the `second' instance encounters. Is there any logical explanation for this?
Thanks!