1

Given

class Foo {
    public:
        bool *b;
        Foo();
};
Foo::Foo()
    :b()
{      
}

int main()
{
    Foo foo;
}

What does the b() do in the class initializer list? It seems to maybe initialize the pointer's value to 0.

1
  • 2
    It makes b be a null pointer Commented Jul 10, 2019 at 4:22

1 Answer 1

3

This is 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.

and

If T is a scalar type, the object's initial value is the integral constant zero explicitly converted to T.

and also

Zero- and value-initialization also initialize pointers to their null values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.