I'm getting tons of errors on my private class members. Please help me work through them.
error: a brace-enclosed initializer is not allowed here before '{' token
error: invalid in-class initialization of static data member of non-integral type 'const char []'
error: 'LETTERS_ARR' has not been declared
error: 'LETTERS_ARR' has not been declared
error: expected ',' or '…' before '+' token
error: ISO C++ forbids initialization of member 'SNTNC_SMLRTY_THRSHLD_DEFAULT'
error: making 'SNTNC_SMLRTY_THRSHLD_DEFAULT' static**
private:
std::vector<std::string> files_vec;
std::vector<std::string> get_file_sntncs(std::fstream&);
std::vector<std::string> get_sntnc_wrds(const std::string&);
double sntnc_smlrty_qtnt(std::vector<std::string>, std::vector<std::string>);
static const char LETTERS_ARR[] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'."};
static const std::set<char> LETTERS_SET(LETTERS_ARR, LETTERS_ARR + sizeof(LETTERS_ARR)/sizeof(char));
double sntnc_smlrty_thrshld;
static const double SNTNC_SMLRTY_THRSHLD_DEFAULT = 0.5;
Best Answer
In C++ you are not allowed to supply in-class initializers for static members of non-integral non-enum type. For such members the initializer is supplied at the point of definition, not at the point of declaration.
Alternatively, as @juanchopanza noted in the comments, you can declare your static members as
constexpr
instead ofconst
(assuming you are using a C++11 compiler), which will permit you to supply in-class initializers for such members just like you do in your original code.