C++ – infer from someones code when they use direct initialization with Curly Braces as opposed to Parenthese

cinitializationqtreading-codevariables

Up until now, I have been initializing most of my variables as such:

const QString foo("bar");

Which from my newfound understanding, is known as direct initialization. (http://en.cppreference.com/w/cpp/language/direct_initialization)

I was looking at someone's code, and in a namespace, they were initializing their variables with Curly Braces:

const QString foo{"bar"};

which also counts as direct initialization:
enter image description here

I never knew this was a thing until today.

Code is more often read than written, what does direct initialization with Curly Braces imply as compared to Parentheses?

Just as I understand a const will tell me that a variable will not change, can I infer anything from this curly brace practice?

Best Answer

This shows that the author is using modern C++ (e.g. >= C++11) and applies good practice:

Braced initialization is the most widely usable initialization syntax, it prevents narrowing conversions and it's immune to C++'s most vexing parse.

-- Scott Meyers, in Effective Modern C++, Item 7

You have to be aware that there might however be a subtlety if a class has a constructor from an initializer list.

If you're not familiar with this syntax, I'd really recommend you to read Scott Meyer's above-mentioned book or acquire equivalent knowledge for example with Herb Sutter's videos, in order not to end up with outdated C++ skills.