在下面的代码中,我收到了这些警告消息:
Member 'year' was not initialized in this constructor
Member 'month'was not initialized in this constructor
Member 'day' was not initialized in this constructor
...
但是,对于 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") { };
为什么这些成员没有被默认初始化,我该怎么办?
最佳答案
您可以使用初始化列表来初始化它们:
UnitTestCInterface()
: year(0),month(0),day(0), filename(nullptr), UnitTest("UNIT TEST: C Interface")
{ };
关于c++ - 为什么这些成员没有被默认初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22600687/