Like so:
T a{};
Pre-C++11, this was the simplest approximation:
T a = T();
But it requires T
be copyable (though the copy is certainly going to be elided).
Related Contents:
- Why can templates only be implemented in the header file?
- initializer_list and move semantics
- C++ templates that accept only certain types
- Variadic template pack expansion
- Can someone explain this template code that gives me the size of an array? [duplicate]
- How to emulate C array initialization “int arr[] = { e1, e2, e3, … }” behaviour with std::array?
- How to detect whether there is a specific member variable in class?
- “Undefined reference to” template class constructor [duplicate]
- Why not infer template parameter from constructor?
- Propagating ‘typedef’ from based to derived class for ‘template’
- std::function vs template
- explicit specialization of template class member function
- C++ Get name of type in template
- Can the template parameters of a constructor be explicitly specified?
- SFINAE to check for inherited member functions
- Determine if a type is an STL container at compile time
- How does this template magic determine array parameter size?
- template member function of template class called from template function
- Template Constraints C++
- A better way to avoid public member invisibility and source code bloat/repetition with inherited class templates?
- Why should I avoid std::enable_if in function signatures
- Template issue causes linker error (C++) [duplicate]
- Template tuple – calling a function on each element
- What is the partial ordering procedure in template deduction
- Templates polymorphism
- trailing return type using decltype with a variadic template function
- Specify template parameters at runtime
- How to achieve “virtual template function” in C++
- constant references with typedef and templates in c++
- C++ preprocessor: avoid code repetition of member variable list
- What do compilers do with compile-time branching?
- How Does std::enable_if work?
- Undefined reference error for template method [duplicate]
- Deduce template argument from std::function call signature
- Lambda expressions as class template parameters
- C++11: Compile Time Calculation of Array
- For nested templates, when did `>>` become standard C++ (instead of `> >`)?
- Template function as a template argument
- Variadic templates
- What does this variadic template code do?
- Why is the STL so heavily based on templates instead of inheritance?
- Name lookups in C++ templates
- Passing const char* as template argument
- Why can’t templates be within extern “C” blocks?
- c++ –
- compile time loops
- Why is the keyword “typename” needed before qualified dependent names, and not before qualified independent names?
- C++ overloaded function as template argument
- Using SFINAE to check for global operator
- C++ template typename iterator