0

Is it legal to do the following in C++:

const T array[3]{ **some expression**, **another expression**, T{ 1 } - array[0] - array[1] }; 

In other words: will the 3rd element always be initialized to 1 - **some expression** - **another expression**?

0

1 Answer 1

2

initializer list uses left to right evaluation, but it is evaluated before the initialization of array.

will the 3rd element always be initialized to 1 - some expression - another expression?

No, and you have even UB with T{ 1 } - array[0] - array[1].

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.