iterator not dereferencable???
Why do I keep getting the "vector iterator is not dereferencable" compiler error?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include<iostream>
#include<vector>
using namespace std;
void print(vector<int>::const_iterator beg, vector<int>::const_iterator end)
{
if (beg != end);
{
cout << *beg << " ";
print(++beg, end);
}
}
int main()
{
vector<int> ivec = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
print(ivec.cbegin(), ivec.cend());
system("pause");
}
|
Remove the
; at the end of line 7
1 2 3 4
|
// if (beg != end);
if (beg != end)
{
// ...
|
Topic archived. No new replies allowed.