How to initialize a vector of vectors on a struct?

c++, vector

Solution

You use `new` to perform dynamic allocation. It returns a pointer that points to the dynamically allocated object.

You have no reason to use `new`, since `A` is an automatic variable. You can simply initialise `A` using its constructor:

vector<vector<int> > A(dimension, vector<int>(dimension));

Problem

If I have a NxN matrix ``` vector< vector<int> > A; ``` How should I initialize it? I've tried with no success: ``` A = new vector(dimension); ``` neither: ``` A = new vector(dimension,vector<int>(dimension)); ```

Original source

Related problems