I need to initialize a static const vector that is a class member.
I have tried:
static const vector<string> vr ({"2", "3", "4"});
static const vector<string> vr = {"2", "3", "4"};
static const vector<string> vr {"2", "3", "4"};
However, none of these work.
I am using Eclipse with mingw. (I have enabled c++11)
Static variable initialization is done outside of the class, like this:
class Example
{
static const vector<string> vr;
// ...
};
const vector<string> Example :: vr ({"hello", "world"});
Declare your static members in your class definition, but define them outside.
class MyClass {
public:
// declaration
static const std::vector<std::string> vec;
};
// definition
const std::vector<std::string> MyClass::vec = ...;
The exception to this is integral types,
class MyClass {
public:
// declaration and definition
static const int MAX_BURRITOS = 5;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With