Commit b07f3afa authored by Marco Bubke's avatar Marco Bubke
Browse files

Initializion with Curly Brackets

Curly brackets for initialization got quite powerful. To not invent a
different style we should use the some style like for rounded brackets.

Change-Id: Id4789fb8d4d7f3980a3a8ce2df999cc57022a2a7
Reviewed-by: Eike Ziller's avatarEike Ziller <>
parent 03d52a2a
......@@ -900,6 +900,27 @@
const QVector<int> values = {1, 2, 3, 4, 5};
\section3 Initialization with Curly Brackets
If you use initialization with curly brackets, follow the same rules as with
round brackets. For example:
class Values // the following code is quite useful for test fixtures
float floatValue = 4; // prefer that for simple types
QVector<int> values = {1, 2, 3, 4, integerValue}; // prefer that syntax for initializer lists
SomeValues someValues{"One", 2, 3.4}; // not an initializer_list
SomeValues &someValuesReference = someValues;
ComplexType complexType{values, otherValues} // constructor call
object.setEntry({"SectionA", value, doubleValue}); // calls a constructor
object.setEntry({}); // calls default constructor
But be careful not to overuse it, to not obfuscate your code.
\section3 Non-Static Data Member Initialization
Use non-static data member initialization for trivial initializations, except in public
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment