I have several vectors of int elements.
Now I want to create a vector of vectors, but I don't want to copy the vectors to the new one. If possible, I'd like to pass them by reference.
Please consider:
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> v1;
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
vector<int> v2;
v2.push_back(4);
v2.push_back(5);
v2.push_back(6);
vector<int> v3;
v3.push_back(7);
v3.push_back(8);
v3.push_back(9);
vector<int>& v4 = v1.front();
vector<int>& v5 = v2.front();
vector<int>& v6 = v3.front();
vector<vector<int> >vall;
vall.push_back(v4);
vall.push_back(v5);
vall.push_back(v6);
for (vector<int>::size_type i = 0; i != v1.size(); ++i) {
cout << vall[0][i] << vall[1][i] << vall[2][i] << endl;
}
return 0;
}
This attempt results in error.
Is there a way to do this?