Added narrowing example in braced list syntax

This commit is contained in:
Gauthier Billot
2017-04-25 10:29:50 +02:00
committed by GitHub
parent b887e0eb55
commit 4ad2d10cc0

View File

@@ -980,6 +980,16 @@ A c = {0, 0}; // calls A::A(int, int)
A d{0, 0, 0}; // calls A::A(int, int, int) A d{0, 0, 0}; // calls A::A(int, int, int)
``` ```
Note that the braced list syntax does not allow narrowing:
```c++
struct A {
A(int) {}
};
A a(1.1); // OK
A b{1.1}; // Error narrowing conversion from double to int
```
Note that if a constructor accepts a `std::initializer_list`, it will be called instead: Note that if a constructor accepts a `std::initializer_list`, it will be called instead:
```c++ ```c++
struct A { struct A {