2d vectors

I get the following errors in trying out the example code @ (http://www.cplusplus.com/forum/general/833/.
The err appeara to be at the ". "on the line that adds the row to the main vector ("row.push_back(i * j); "). I stuck this code in my class constructor. I also tried tried several methods with the same results and other negative results.
Method a: By placing the vector declaration in the .h file and the definition in the .cpp file.
Method b: Both declaration and definition in the .cpp file.

I'm stuck and don't get the err. Any help is greatly appreciated. How do I implement this animal in a class?
I feel bruised and abused by this 2D vector (Better array) animal. For I've spend an ungodly amount of time in books and the net with no success.

I'm using MS. VS 2010.
Thanks in advance

The 2 errors are:
error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::vector<_Ty> &&'

IntelliSense: no instance of overloaded function "std::vector<_Ty, _Ax>::push_back [with _Ty=std::vector<char, std::allocator<char>>, _Ax=std::allocator<std::vector<char, std::allocator<char>>>]" matches the argument list

This is the code.
vector< vector<int> > vec;
for (int i = 0; i < 10; i++) {
vector<int> row; // Create an empty row
for (int j = 0; j < 20; j++) {
row.push_back(i * j); // Add an element (column) to the row
}
vec.push_back(row); // Add the row to the main vector
}
Last edited on
The error message says that the vector is an std::vector<char>. This doesn't match the code you've posted. Please post the code that's generating the error.
Topic archived. No new replies allowed.