If I create a vector of vectors of double:
std::vector< std::vector<double> > table1;
Are my vectors of doubles uninitialized?
In fact, at this point, you have *no* vector<double>s at all. The "outer"
vector that is supposed to contain vector<double>s has zero size. No
memory has been allocated at all for storing vector said:
Do I have to loop through table1
and initialize each vector of doubles using new?
Assuming you know how big the table is supposed to be (numRows x numCols)
at run time, before you declare the table, the easiest way is to make the
table the appropriate size when you declare it:
std::vector<std::vector<double> > table1 (numRows,
std::vector<double>(numCols));
Then fill the table using the usual table1[row][col] notation.
And in cleaning up, manually delete each of these vectors of doubles?
No, std::vector's destructor will take care of any cleanup that is
necessary, in this case. If you had declared a vector of pointers, then
you would need to either delete the pointers individually or make sure
other pointers are pointing to the objects being pointed to, before the
vector goes out of scope. But you still wouldn't have to worry about
deleting the vector itself, because you didn't use new to create it.