deque and iterators

what is the deal?
I cannot seem to get the following to compile:



deque<(user defined type)*> history;

if(!history.empty() ) {
for(deque<(user defined type)*>::iterator i = history.front();
i != history.end(); ++i) {

cout << *i << endl;
}
}

I am constantly getting C2440 error in MSVS 2010.
What does the error say?
1>c:usersrandondocumentsvisual studio 2010projectscollectablestorecollectablestorecustomer.cpp(24): error C2440: 'initializing' : cannot convert from 'Transaction *const ' to 'std::_Deque_iterator<_Ty,_Alloc>'
1> with
1> [
1> _Ty=Transaction *,
1> _Alloc=std::allocator<Transaction *>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous

where Transaction is my own user defined type
and it also says the = sign in the for loop is the culprit
front returns a reference, to get an iterator use begin

And please use [code][/code] tags
Last edited on
damn, I was messing with it too much and forgot about that. I am still getting a similar error.

changed
history.front()
to
history.begin()

and now the error message is:

1>c:usersrandondocumentsvisual studio 2010projectscollectablestorecollectablestorecustomer.cpp(24): error C2440: 'initializing' : cannot convert from 'std::_Deque_const_iterator<_Ty,_Alloc>' to 'std::_Deque_iterator<_Ty,_Alloc>'
1> with
1> [
1> _Ty=Transaction *,
1> _Alloc=std::allocator<Transaction *>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
I was playing around with it and I suddenly realized it could possibly matter that my deque was declared in the .h, which it seems to, because when I add it to the .cpp next to the print statement it works. now how do I fix it where it works being declared in the .h?
The problem that the error is trying to say is that history is a const object, so you need to use a const_iterator rather than an iterator
crazy, I havent heard of a const_iterator yet. thank you for your help, it seems to be working.

Randon
Topic archived. No new replies allowed.