8

I have a basic question. I have a class with a data member : double _mydata[N]. (N is a template parameter). What is the syntax to initialize these data to zero with a constructor initialization list ? Is _mydata({0}) OK according to the C++ standard (and so for all compilers) ?

Thank you very much.

1
  • Well, I think you could answer half of your question on your own rather easily since _mydata({0}) wouldn't even compile. Commented May 22, 2012 at 0:52

1 Answer 1

12

No, prior to C++11 you need to do just this to default-initialise each element of the array:

: _mydata()

The way you have it written won't work.

With C++11 it is more recommended use uniform initialisation syntax:

: _mydata { }

And that way you can actually put things into the array which you couldn't before:

: _mydata { 1, 2, 3 }
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.