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).
More Related Contents:
- Where and why do I have to put the “template” and “typename” keywords?
- overloading friend operator
- Variadic template pack expansion
- “Undefined reference to” template class constructor [duplicate]
- std::function vs template
- initializer_list and template type deduction
- Advantages of auto in template parameters in C++17
- C++ Get name of type in template
- Implicit type conversion with template
- Why doesn’t a derived template class have access to a base template class’ identifiers?
- Template template parameters
- How do I define a template function within a template class outside of the class definition?
- Template partial ordering – why does partial deduction succeed here
- C++14 Variable Templates: what is their purpose? Any usage example?
- How does the compilation of templates work?
- How can I check if a type is an instantiation of a given class template? [duplicate]
- C++ template friend operator overloading
- For nested templates, when did `>>` become standard C++ (instead of `> >`)?
- void_t “can implement concepts”?
- How can I output the value of an enum class in C++11
- Templated class specialization where template argument is a template
- Why can I call base template class method from derived class
- Template typedefs – What’s your work around?
- Deciphering C++ template error messages
- Implicit conversion when overloading operators for template classes
- Switch passed type from template
- pointer as non-type template argument
- Obtain container type from (its) iterator type in C++ (STL)
- Const and non const template specialization
- How does std::forward receive the correct argument?