Initialization Types

closed account (zybCM4Gy)
http://www.cplusplus.com/doc/tutorial/variables/

The tutorial tells me that there are three ways to initialize variables.

c-like initialization
constructor initialization
uniform initialization

What's the difference between them? I want to know which one I should be using when effectively. Some places state that I should be using a lot the uniform initialization....

http://isocpp.org/blog/2012/12/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax

Yet at the same time point out that it's likely to cause problems (:S). At the moment
Yet at the same time point out that it's likely to cause problems
If you don't know what is it doing. It will try to call a constructor which takes initialization list as a parameter first and fall back to regular constructor call (like if you replace {} with parenteses) if it is not possible.
I would say use constructor initialization if you need to call specific constructor (like constructor which takes number of elements and value for vector) to avoid confusion and use uniform initializaton if you need initializer list constructor (because ({..}) looks ugly) or you need to value initialize array.

All of them does the same thing: initializes object. Which to use is a matter of personal preference, code conventions and clarity.
Topic archived. No new replies allowed.