Fix incorrect (ill-formed) example for class template argument deduction

This commit is contained in:
Richard Smith
2016-11-11 16:47:25 -08:00
committed by GitHub
parent 6bb6ec1961
commit a633a217ea

View File

@@ -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