我在Linux机器上使用版本为1.85的cppcheck
时遇到了一个警告:
someFile.h:23:29: 警告: 冗余代码: 发现以字符串常量开头的语句。[constStatement]
const std::string OffOn[]= {"off", "on"};
^
我做了一些研究,发现将这个语句更改为
const std::string OffOn[]= {std::string("off"), std::string("on")};
移除了警告。然而,我不理解发生了什么,以及我的第一种解决方案有什么“不好”的地方。或许有人可以向我解释一下?或者给我一些提示!
const std::string OffOn[]{"off", "on"};
,因此=
是不必要的。 - Denis Sablukov