mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 01:54:36 +03:00
Merge pull request #21 from gogoprog/feature/narrowing-braced-list
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)
|
||||
```
|
||||
|
||||
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:
|
||||
```c++
|
||||
struct A {
|
||||
|
||||
Reference in New Issue
Block a user