STL vector initial value
when a vector of c++ datatypes is created, is it always set to 0 or "" or is it platform/implementation dependent?
I know that in VS, this is the case but wonder if this will cause a problem on different compilers.
[223 byte] By [
rssmps] at [2007-11-11 10:30:04]

# 1 Re: STL vector initial value
Which datatypes are you referring to? Built-in ones? In that case, the vector will use T() as the initializer, e.g., int(), double() etc. The effect of such an expression:
int n= int();
is default initializing n, which in the case of fundamental types means zero initialization, or initialization with zero converted to the target type, e.g., false, null pointer value etc.
Danny at 2007-11-11 20:58:37 >

# 2 Re: STL vector initial value
yeah, built in ones.
I need val in the code to be all 0 and wanted to make sure I don't get a vector of 12 garbage values.
if(padWithZeros)
{
vector<double> val(12);
for(int j=size; j<12; j++)
{
matrix.push_back(val);
}
}
rssmps at 2007-11-11 20:59:42 >

# 3 Re: STL vector initial value
If you want to be 100% sure about the default values, you can use a more explicit form:
vector<double> val(12, 0.0); //allocate 12 doubles initialized to 0.0
Danny at 2007-11-11 21:00:41 >
