c++ - allocating vectors (or vectors of vectors) dynamically -


i need dynamically allocate 1-d , 2-d arrays sizes given @ run-time.

i managed "discover" std::vector , think fits purposes, ask whether i've written correct and/or can improved.

this i'm doing:

#include <vector>  typedef std::vector< std::vector<double> > matrix;  //... various code , other stuff  std::vector<double> *name = new std::vector<double> (size); matrix *name2 = new matrix(sizex, std::vector<double>(sizey)); 

dynamically allocating arrays required when dimensions given @ runtime, you've discovered.

however, std::vector wrapper around process, dynamically allocating vectors double positive. it's redundant.

just write:

#include <vector>  typedef std::vector< std::vector<double> > matrix; matrix name(sizex, std::vector<double>(sizey)); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -