POV-Ray : Newsgroups : povray.off-topic : Smart little programming tricks, where to find ? : Re: Smart little programming tricks, where to find ? Server Time
11 Oct 2024 01:21:58 EDT (-0400)
  Re: Smart little programming tricks, where to find ?  
From: Warp
Date: 20 Mar 2008 03:48:12
Message: <47e224cc@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.