Public Group

# STL deque iterator issue

This topic is 2945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all. I usually don't run to post when I have a problem, but this one has been frustrating me for over an hour now, and I don't have a clue on how to fix it.

for (deque<Bullet>::iterator it = deqBullet.begin(); it != deqBullet.end(); it++)	{		...	}

Why won't this work? I tried breaking it up, and still nothing.

deque<Bullet>::iterator it;for (it = deqBullet.begin(); it != deqBullet.end(); it++)	{		...	}

My errors are:

Error	8	error C2440: 'initializing' : cannot convert from 'std::_Deque_iterator<_Ty,_Alloc,_Secure_validation>' to 'std::_Deque_iterator<_Ty,_Alloc,_Secure_validation>'	Error	9	error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Deque_iterator<_Ty,_Alloc,_Secure_validation>' (or there is no acceptable conversion)	Error	10	error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::_Deque_iterator<_Ty,_Alloc,_Secure_validation>' (or there is no acceptable conversion)

I am very inexperienced with containers and algorithms (next semester), but I am trying to muscle this one in. I do okay with vectors, but this piece of the game wouldn't work with a FILO container. Any suggestions for a better way to do an array of bullet objects (that are deleted once they are out of bounds) would be appreciated as well. Thank you,

Dan

Edit: Sorry the post came out so wide, I didn't see a way to restrict some type of word-wrap for the code.

##### Share on other sites
The error message implies some sort of type mismatch. It implies they're both deques -- double check that deqBullet isn't a std::deque<int> or something.

EDIT: The only other thing I could think of is possibly if this is a const member function, and deqBullet is also a member variable. If that's the case, you'd want to use const_iterator instead of iterator, assuming your loop only reads from deqBullet. If it modifies the contents, then the member function probably shouldn't be const.

If it's none of these, you should post more code, there's nothing obviously wrong in what you've shown. You could also look at the "Output" tab -- it will show you what _Ty, _Alloc, and _Secure_validation are in those errors.

EDIT: To give an example of what we can look for in the future:

#include <deque>struct Bullet {};int main() {	std::deque<int> bullets;	std::deque<Bullet>::iterator i = bullets.begin();}

Output1>------ Build started: Project: test, Configuration: Debug Win32 ------1>Compiling...1>main.cpp1>i:\home\projects\new\test\test\main.cpp(7) : error C2440: 'initializing' : cannot convert from 'std::_Deque_iterator<_Ty,_Alloc,_Secure_validation>' to 'std::_Deque_iterator<_Ty,_Alloc,_Secure_validation>'1>        with1>        [1>            _Ty=int,1>            _Alloc=std::allocator<int>,1>            _Secure_validation=true1>        ]1>        and1>        [1>            _Ty=Bullet,1>            _Alloc=std::allocator<Bullet>,1>            _Secure_validation=true1>        ]1>        No constructor could take the source type, or constructor overload resolution was ambiguous1>Build Time 0:001>Build log was saved at "file://i:\home\projects\new\test\test\Debug\BuildLog.htm"1>test - 1 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If it's a const issue, one might see "const Bullet" instead of "int".

##### Share on other sites
Quote:
 Original post by Soaps79My errors are:

Look at the rest of each error message. There should be more info, where the template values '_Ty' etc. are expanded for the left and right sides.

##### Share on other sites
Quote:
 Original post by MaulingMonkeyThe error message implies some sort of type mismatch.

I took a break and came back to it, and as soon as I read that, I face-palmed. When I originally made it a Vector, it was a vector of Bullet*'s, so I could allocate them as I went. When I stumbled through changing it to a Deque, I lost sight of that and didn't properly treat them as pointers.

Thanks all.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 10
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632647
• Total Posts
3007640
• ### Who's Online (See full list)

There are no registered users currently online

×