gpt4 book ai didi

c++ - 错误 : invalid in-class initialization of static data member of non-integral type 'const char[]'

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:47:23 26 4
gpt4 key购买 nike

我的私有(private)类(class)成员出现大量错误。请帮助我解决这些问题。

错误:在“{”标记之前不允许使用大括号括起来的初始值设定项

错误:非整数类型“const char []”的静态数据成员的类内初始化无效

错误:“LETTERS_ARR”尚未声明

错误:“LETTERS_ARR”尚未声明

错误:在“+”标记之前需要“,”或“...”

错误:ISO C++ 禁止初始化成员“SNTNC_SMLRTY_THRSHLD_DEFAULT”

错误:将“SNTNC_SMLRTY_THRSHLD_DEFAULT”设为静态**

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;

最佳答案

在 C++ 中,不允许为非整数非枚举类型的静态成员提供类内初始化器。对于此类成员,初始化程序是在定义时提供的,而不是在声明时提供的。

或者,正如@juanchopanza 在评论中指出的那样,您可以将静态成员声明为 constexpr 而不是 const (假设您使用的是 C++11 编译器) ,这将允许您像在原始代码中那样为此类成员提供类内初始化器。

关于c++ - 错误 : invalid in-class initialization of static data member of non-integral type 'const char[]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20279945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com