C++: vector <pair<vector<int>,int> >

10,259

Solution 1

vector<pair<vector<int>,int> > var_name(x, make_pair(vector<int>(y), 0));

Solution 2

Simplify it as:

pair<vector<int>,int> value(vector<int>(y), 0);
vector<pair<vector<int>,int> > var_name(x, value);

If you like your own syntax, then you should be doing this:

vector<pair<vector<int>,int> > var_name(x, std::make_pair(vector<int>(y), 0));

Solution 3

You can use make_pair from <utility> to construct the pair you wish to initialize your vector with. For example:

vector< pair<vector<int>,int> > var_name(x, make_pair(vector<int>(y), 42))

or call the pair<vector<int>,int> constructor directly (as it looks like you're trying to):

vector< pair<vector<int>,int> > var_name(x, pair<vector<int>,int>(vector<int>(y), 0))

Share:
10,259
Jimmy Huch
Author by

Jimmy Huch

Updated on June 04, 2022

Comments

  • Jimmy Huch
    Jimmy Huch almost 2 years

    This is what I am aiming to do...

    vector < pair<vector<int>,int> > var_name (x, pair <vector<int>(y),int>);
    

    Where x is the size of the vector var_name and y is the size of the vector inside the pair.

    The above statement doesn't work because the pair template only allows constants. How can I go about getting both my vectors to size to x and y respectively?