[英]Why are these members not being default initialized?
In the following code, I get these warning messages: 在以下代码中,我得到了这些警告消息:
Member 'year' was not initialized in this constructor
未在此构造函数中初始化成员“ year”
Member 'month'was not initialized in this constructor
成员“ month”未在此构造函数中初始化
Member 'day' was not initialized in this constructor
成员“ day”未在此构造函数中初始化
...
...
However, I would expect the members to be default initialized to, say, 0 for the uint32_t types. 但是,我希望将uint32_t类型的成员默认初始化为0。
typedef uint32_t bmd2_uint32;
class UnitTestCInterface : public UnitTest {
{
private:
bmd2_uint32 year;
bmd2_uint32 month;
bmd2_uint32 day;
...
public:
UnitTestCInterface()
: filename(nullptr), UnitTest("UNIT TEST: C Interface") { };
How come these members aren't being default initialized, and what can I do about it? 这些成员为什么没有被默认初始化,我该怎么办?
You can initialize them using an initialization list: 您可以使用初始化列表来初始化它们:
UnitTestCInterface()
: year(0),month(0),day(0), filename(nullptr), UnitTest("UNIT TEST: C Interface")
{ };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.