"Expression: deque iterator not dereferencable" can't think of a fix :(

May 25, 2009 at 9:29pm
apparently deque iterators are not dereferencable...

the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Player
{
public:
	Player():points(0){}
	~Player(){}
	void AddCard( std::deque<Card>::iterator cardtoadd ){ hand.push_back(*cardtoadd); }
private:
	std::deque <Card> hand;
	int points;
};


void Deal(std::vector <Player> *players, std::deque <Card> *deck)
{
	for(std::vector<Player>::iterator player = players->begin(); player != players->end(); player++)
	{
		for( int cardcount = 0; cardcount < 7; cardcount++ )
		{
			std::deque<Card>::iterator object = deck->end();
			player->AddCard(object);
		}
	}
}


produces a Debug Assertion Failed error when the program gets to line 21 on here.

"Expression: deque iterator not dereferencable"

but the program compiles fine.

i can't think of a way around this and i tried many things.
Last edited on May 25, 2009 at 9:32pm
May 25, 2009 at 9:37pm
 
deck->end()

Isn't really part of your deque container, and so you can't deference an iterator that points to it. Remember that end() always returns one past the last element of the container. You probably want deck->back() instead, if you want to access the last element.
Last edited on May 25, 2009 at 9:45pm
May 25, 2009 at 10:06pm
thanks :)

im really loving these forums and community lol.
Topic archived. No new replies allowed.