A
A
AlexeiNe2016-03-05 07:20:53
C++ / C#
AlexeiNe, 2016-03-05 07:20:53

What are the curly braces after a variable declaration in C++?

I'm reading the book Learn C++ for Game Development by Bruce Sutherland
In one of the examples I found a strange declaration of a variable:
unsigned int playersNumber {};
The declaration itself is simple and understandable, but I can't figure out what the curly braces are for. Could this be the new C++11 standard?
The example works both with and without them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SMA2, 2016-03-05
@AlexeiNe

Initialization with an empty value.
This is a generic notation for various types of variables.
In this case, we are talking about an integer, therefore it is equivalent to = 0
But curly braces are a more general method, suitable for variables of various types.
That the example works without initialization is just luck.
Using an uninitialized variable is a common mistake.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question