suggest i have a template function like following:
template
void doSomething()
{
T a; // a is correctly initialized if T is a class with a
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).
Class template field in C++11 has the same syntax:
template <class T>
class A {
public:
A() {}
A(T v) : val(v) {}
private:
T val{};
};