Given a templated C++ function in C++-03:
template <typename data>
void example(data arg) {
// How to get POD zero initialized and non-POD, default constructor?
data x();
...
}
How can I zero out a templated argument if it is POD (e.g. int
gets a 0
, float
gets a 0.0
, etc.) or, for non-POD, use its default constructor?
I see with class members, this is handled as explained here with:
struct X
{
int x;
};
X x; //x.x is not initialized
X y = X(); //y.x is 0
But in this situation, the variable is not a member of a class, so how do you correspondingly get this effect of initializing a POD typed variable and default constructing a non-POD typed variable?