Home > Software engineering >  Difference between these 2 types of vector initialization
Difference between these 2 types of vector initialization

Time:10-15

I tried to search online but didn't found any information. Is vector adj[x] a type of 2d vector initialization?

vector <vector<int>> test(2);
vector <int> adj[2];

Their gdb details are also different.

(gdb) p test
$2 = std::vector of length 2, capacity 2 = {std::vector of length 0, capacity 0, std::vector of length 0, capacity 0}
(gdb) p adj
$3 = {std::vector of length 0, capacity 0, std::vector of length 0, capacity 0}

CodePudding user response:

The first is a vector of vectors, where the 2 is the argument to the constructor.

The second is an c-style array of vectors, where [2] indicates the number of vectors in the array. There's no constructor argument given here.

  • Related