I've got a struct foo bar of the form struct foo { const char* s, ... }; and a std::vector<foo> v; and I want to push_back a few foo's with constant values for the s member field, i.e.
bar.push_back({ "1", /*...*/ }); bar.push_back({ "2", /*...*/ }); bar.push_back({ "3", /*...*/ }); //... Now, if I'm not totally wrong, this isn't safe, since the life time of the string literals are bounded to the scope of the initializer braces. So, the life time of the string literal "1" should have already been ended at the line of the second push_back.
How can we deal with this? Do we really need to create a second container strong std::string's and passing the corresponding c_str() pointers to bar?