Clazy 输出非 pod-global-statics 的警告。我明白为什么这会减慢代码速度,但不知道更好的解决方案是什么?例如,在这个简单的头文件中:
模块1.hpp
#include <string>
#include <vector>
const std::vector<std::string> namesVec{"name1", "name2", "name3"};
static const std::string name{"name1"};
class Module1
{
public:
Module1();
~Module1();
void func1();
};
其中有两个警告,分别针对
namesVec
和 name
。避免这些警告的最佳方法是什么?
使用字符串文字直接创建 std::string,而不是从 const char* 创建并复制它。
using namespace std::string_literals;
static const auto mystr = "hello"s;