你如何处理"warning #370-D: class "match_str“没有定义构造函数”
How do you handle "warning #370-D: class "match_str" defines no constructor"
结构如下:
struct match_str {
const char* s; // Pointer to string
const uint8_t l; // Length
};
只打算初始化如下:
const match_str s = {"200 OK", 5};
并用作具有常量成员的普通结构。在编译期间,我收到以下警告:
warning #370-D: class "match_str" defines no constructor to initialize the following: const member "match_str::l"
我可以用警告做什么?我收到警告,这是有道理的,但我不确定如何处理。基本上,这是我在代码中使用的 更安全 c 字符串结构,每个实例都是手写的,就像 const char*
参考:
Is this warning alright - "#368-D: <entity> defines no constructor to initialize the following:"?
warning #411: class foo defines no constructor to initialize the following:
只需删除结构中的 const
,并使结构的实例成为 const
,这将达到保持成员不变的目的。
结构如下:
struct match_str {
const char* s; // Pointer to string
const uint8_t l; // Length
};
只打算初始化如下:
const match_str s = {"200 OK", 5};
并用作具有常量成员的普通结构。在编译期间,我收到以下警告:
warning #370-D: class "match_str" defines no constructor to initialize the following: const member "match_str::l"
我可以用警告做什么?我收到警告,这是有道理的,但我不确定如何处理。基本上,这是我在代码中使用的 更安全 c 字符串结构,每个实例都是手写的,就像 const char*
参考:
Is this warning alright - "#368-D: <entity> defines no constructor to initialize the following:"?
warning #411: class foo defines no constructor to initialize the following:
只需删除结构中的 const
,并使结构的实例成为 const
,这将达到保持成员不变的目的。