When I declare a vector like vector<vector<int> >v
and try to pass it to a function like below it works:
int change(vector<vector<int> >&v)
{
v[0][0]=-1;
}
int main()
{
vector<vector<int> >v;
int a[]={1,2,3};
int b[]={4,5,6};
v.push_back(vector<int>(a,a+3));
v.push_back(vector<int>(b,b+3));
change(v);
cout<<v[0][0];
return 0;
}
But when I declare the vector like vector<int>v[2]
and pass it to a function in the same way it's causing an error.
int change(vector<vector<int> >&v)
{
v[0][0]=-1;
}
int main()
{
vector<int>v[2];
int a[]={1,2,3};
int b[]={4,5,6};
v[0]=vector<int>(a,a+3);
v[1]=vector<int>(b,b+3);
change(v);
cout<<v[0][0];
return 0;
}
How can I do this and why is this causing an error?