I am working with templates in C++ and want to know how can we properly(value) initialize the non static data members in a class template. For example, consider the following snippet:
template<typename T>
class MyVector
{
T x; // x has undefined value for a built in type
};
Now i know that the data member x
has garbage value for built in types in local/block scope unless explicitly initialized.
So i want to value initialize the data member. If i modify the above code to:
template<typename T>
class MyVector
{
T x(); // now x becomes a member function
};
As can be seen in the above modified code snippet, x
is now a member function. How can i value initialize the data member x
for type T
?