1

I want to push_back only one column in a multidimensional vector. How do I only access and push_back the vector at a specific row with an int?

typedef vector<int> Row;
typedef vector<Row> Matrix;
int N = 3;
Matrix restricted(N+1, Row(0));

And then after I run the following "working" code, the table will look like the one below.

restricted[2].push_back(3);

Resultant (array-formatted) vector: {{}, {}, {3}, {}}

restricted[2].push_back(100);
restricted[0].push_back(99);

Resultant (array-formatted) vector: {{99}, {}, {3, 100}, {}}

Resultant error when above code run: no matching function for call to 'std::vector<int>::push_back(<unresolved overloaded function type>)'

  • 2
    Can you please explain your question in detail? I mean, you want to `push_back` a `Row`, or an element in a `Row`? – shauryachats Jan 19 '15 at 08:44
  • 1
    I just want to know the syntax of a statement which adds an 'int' value to the end of a nested (multidimensional) vector, without needing to push_back an entire vector into the outer vector container. –  Jan 19 '15 at 08:46
  • 1
    I want to push back an element in a Row –  Jan 19 '15 at 08:46
  • 1
    You did `restricted[2].push_back(3);`, pushing back an element in a `restricted` multidimensional vector. This statement is correct. – shauryachats Jan 19 '15 at 08:51
  • Please see error message above. –  Jan 19 '15 at 08:53
  • 2
    I ran this program on http://ideone.com/KmDfQe and it compiled successfully. Please show the entire code. – shauryachats Jan 19 '15 at 08:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69107/discussion-between-shaurya-chats-and-apoorvk). – shauryachats Jan 19 '15 at 08:59

0 Answers0