The purpose of uniform initialization is to be a single means of initializing any object which can be initialized. It therefore can pick and choose the appropriate initialization mechanism to use internally for a particular type.
Point
is an aggregate. In C++98/03, it therefore could be initialized with aggregate initialization, much like an array.
Point p = {3, 4};
That was legal in C++98/03.
In C++11, aggregate initialization is one of the possible ways for uniform initialization to initialize a variable. If the type being initialized is an aggregate, then the members of the braced-init-list are used to initialize it via aggregate initialization. But aggregate initialization in C++98/03 only worked in Typename var = braced-init-list;
form. Uniform initialization allows all of these forms to use it as well:
Point p{3, 4};
void Func(const Point &p);
Func({3, 4});
Point Func2()
{
return {3, 4};
}
All of these use uniform initialization to initialize a Point
aggregate. However, since it's using uniform initialization syntax, you can later change Point
to add a constructor. And as long as you add a constructor that takes two integers (and don't add an initializer_list
constructor that takes integers), all your code will work just fine.