0
vector<int> iv;
	iv.push_back(4);
	vector<int>::iterator it = iv.begin();
	cout << *it;

	cout << *(iv.begin()); //debug assertion here

Why can't I dereference iv.begin() directly?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Jsplinter
0

Compiles (and runs) using gcc, too. Here's my entire program, built from your snippet:

#include "vector"
#include "iostream"

using namespace std;

int main ()
{
	vector<int> iv;
	iv.push_back(4);
	vector<int>::iterator it = iv.begin();
	cout << *it;

	cout << *(iv.begin()); //debug assertion here
	return 0;
}

This doesn't compile on your system?

0

Hmm, I have no idea why it is causing a problem on my system. It compiles but throws an exception in debug mode. I thought it should certainly work. But The code was cut and pasted and it wasn't working in debug mode of VS2010. I thought I was losing my mind. Glad to know that something else was going on.

Edited by Jsplinter: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.