Mail Archives: djgpp/1999/10/08/12:41:44
>Yes, but not quite the problem I'm trying to
>solve. I understand about checked or unchecked
>indexing, but how do I pre-allocate for a
>particular size of matrix?
>
>vector<int> a(10); allocates a one-d vector of
>ten elements. I want to do something like
>
>vector< vector<int>(10) > a(10); to allocate a
>matrix with ten rows and ten columns, instead of
>doing
>
>int a[10][10];
>
>I'm not sure this is possible with the STL.
>Perhaps I need to write a two-d matrix class?
>
The way I would do this is
vector<vector<int> > a(10);
for_each(a.begin(), a.end(),
bind2nd(mem_fun1(&vector::resize), 10));
Make sure to #include <algorithm> and <functional>
as well as <vector>. Not the most elegant solution
in the world, but still better than having to write
a for loop every time you want to do it, and of
course you could write your own function to do what
the second line of code does for you.
Hope it helps.
Kenn
=====
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
- Raw text -