C++ dynamic array of matrices (from scythe statistical library)
I am trying to use the scythe statistical library (found here: http://scythe.wustl.edu/). I can initialize a matrix just fine with:
Matrix<double> A(2, 2, false);
But I would like to have a dynamic array of such matrices. Does anyone have any hints? Do I use vector? If so how?
Many thank开发者_Python百科s!
A std::vector
would be an excellent choice, especially if you don't know until runtime how many matrices you need. For example,
std::vector<Matrix<double> > vectorOfMatrices;
vectorOfMatrices.push_back(Matrix<double>(2, 2, false));
// etc.
There are two classes suitable for your task:
a) std::vector - stores the objects in an array, can be accessed via index as well as iterator. Good for random access operations.
b) std::list - stores objects as a linked-list, accessed via iterators. Good for sequential-only access and frequent modifications.
So, if you just want an array of fixed or only rarely-changing size, go for std::vector. However, if you know these will change rather often, and you typically iterate over the whole thing, std::list is a better alternative.
精彩评论