I have the following code in test.cpp
:
#include <vector>
#include <string>
class A {
public:
static const std::vector<std::string> foo;
};
const std::vector<std::string> A::foo {{"bar", "baz"}};
int main() {}
It compiles, but when I run it, I get the following error:
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
Aborted (core dumped)
Why am I getting this error?
Hopefully irrelevant: I'm using g++ 4.8.2, with -std=c++11
.
Aside: I purposely initialized foo
outside the class. If I do it inside the class, the compiler tells me that an out-of-class initialization is required (which is ridiculous, imo).