Agrudge Amicus
Agrudge Amicus

Reputation: 1103

Why object in vector of vectors doesn't get created

In this code:

vector<vector<int> > outer_vec;
outer_vec.push_back(vector<int> inner_vec);  //THIS FAILS

but this one:

vector<vector<int> > outer_vec;
vector<int> inner_vec;
outer_vec.push_back(inner_vec);  //THIS WORKS FINE

All in all why in first case the object inner_vec is not getting created.

Upvotes: 0

Views: 43

Answers (1)

GBlodgett
GBlodgett

Reputation: 12819

Your syntax is incorrect. If you just want to push back a new vector it should be:

std::vector<std::vector<int>> outer_vec;
outer_vec.push_back(std::vector<int>());

Where you just create a new vector with std::vector<int>()

Upvotes: 3

Related Questions