mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 10:04:35 +03:00
Added narrowing example in braced list syntax
This commit is contained in:
10
README.md
10
README.md
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user