Message-ID: <19991008135627.27300.rocketmail@web117.yahoomail.com> Date: Fri, 8 Oct 1999 06:56:27 -0700 (PDT) From: Kenn Hamm Subject: Re: vector of vectors To: djgpp AT Delorie DOT com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Reply-To: djgpp AT delorie DOT com >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 a(10); allocates a one-d vector of >ten elements. I want to do something like > >vector< vector(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 > a(10); for_each(a.begin(), a.end(), bind2nd(mem_fun1(&vector::resize), 10)); Make sure to #include and as well as . 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