mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 18:14:36 +03:00
Fix incorrect (ill-formed) example for class template argument deduction
This commit is contained in:
@@ -75,14 +75,15 @@ C++11 includes the following new library features:
|
|||||||
### Template argument deduction for class templates
|
### Template argument deduction for class templates
|
||||||
Automatic template argument deduction much like how it's done for functions, but now including class constructors.
|
Automatic template argument deduction much like how it's done for functions, but now including class constructors.
|
||||||
```c++
|
```c++
|
||||||
template <typename T>
|
template <typename T = float>
|
||||||
struct MyContainer {
|
struct MyContainer {
|
||||||
T val;
|
T val;
|
||||||
|
MyContainer() : val() {}
|
||||||
MyContainer(T val) : val(val) {}
|
MyContainer(T val) : val(val) {}
|
||||||
// ...
|
// ...
|
||||||
};
|
};
|
||||||
MyContainer c1{ 1 }; // OK MyContainer<int>
|
MyContainer c1{ 1 }; // OK MyContainer<int>
|
||||||
MyContainer c2; // OK MyContainer<>
|
MyContainer c2; // OK MyContainer<float>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Declaring non-type template parameters with auto
|
### Declaring non-type template parameters with auto
|
||||||
|
|||||||
Reference in New Issue
Block a user