Link to home
Start Free TrialLog in
Avatar of TwentyFourSeven
TwentyFourSeven

asked on

Vectors of Vectors

Is my misunderstanding of C++ vectors flawed ?

vector<vector<int> > myVec(10,vector<int>(8));
cout << myVec[9][8] << endl;
cout << myVec[10][8] << endl;

0
Bus error


What's up with element 10 ?
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TwentyFourSeven
TwentyFourSeven

ASKER

If that is the case, why is it allowing me to access elemet 8 of the inner vector ?
vector<vector<int> > myVec(10,vector<int>(8));
cout << myVec[9][8] << endl;
0
Program exited normally.
(gdb)
>> If that is the case, why is it allowing me to access elemet 8 of the inner vector ?

It's not because it might work in some cases that it's not wrong.