|
|
Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
> On Thu, 20 Mar 2008 00:52:55 +0100, stbenge <stb### [at] hotmailcom> wrote:
> > Say I wrote
> >
> > int** foo = NULL;
> > int nx = 22, ny = 17;
> >
> > void matrixfunc(){
> > foo = new int*[nx];
> >
> > for (int x = 0; x < nx; x++)
> > foo[x] = new int[ny];
> > }
> Much better to use std::vector instead. Avoid raw pointers like the
> plague; it will save you many headaches.
Yeah. You can do that with a one-liner:
std::vector<std::vector<int> > foo(nx, std::vector<int>(ny));
And you don't have to delete anything.
--
- Warp
Post a reply to this message
|
|