class初始化中的指针初始化
Pointer initialization in class initialization
给出
class Foo {
public:
bool *b;
Foo();
};
Foo::Foo()
:b()
{
}
int main()
{
Foo foo;
}
b()
在 class 初始化列表中有什么作用?似乎可以将指针的值初始化为 0.
这是value initialization; as the effect, built-in types will be zero-initialized. That means b
will be initialized to 0
(the null pointer).
4) otherwise, the object is zero-initialized.
和
If T is a scalar type, the object's initial value is the integral constant zero explicitly converted to T.
还有
Zero- and value-initialization also initialize pointers to their null values.
给出
class Foo {
public:
bool *b;
Foo();
};
Foo::Foo()
:b()
{
}
int main()
{
Foo foo;
}
b()
在 class 初始化列表中有什么作用?似乎可以将指针的值初始化为 0.
这是value initialization; as the effect, built-in types will be zero-initialized. That means b
will be initialized to 0
(the null pointer).
4) otherwise, the object is zero-initialized.
和
If T is a scalar type, the object's initial value is the integral constant zero explicitly converted to T.
还有
Zero- and value-initialization also initialize pointers to their null values.