Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list::iterator & const 2

Status
Not open for further replies.

AMosmann

Programmer
May 27, 2003
82
0
0
DE
if I want to declare a copy-constructor or a operator= like

X::X(const X &x);
X &X::eek:perator={const X &x};


x has a member std::list<AnyType>;

if I do the following:
X::X(const X &x){
std::list<AnyType>::iterator it=x.anylist.begin();
...
};


the compiler tells me:

error C2679:
binary operator '=' : No operator '=', that accepts a righthand operator
'class std::list<class AnyType,class std::allocator<class AnyType> >::const_iterator'


[COLOR=$991111]Binaerer Operator '=' : Kein Operator definiert, der einen rechtsseitigen Operator vom Typ 'class std::list<class AnyType,class std::allocator<class AnyType> >::const_iterator' akzeptiert (oder keine geeignete Konvertierung moeglich)[/color]

how can I step through a const list ?
the way I found was to copy the list and step throuug this one, but there must be other ways, isn't?



Greetings Andreas
 
You can try this, maybe it would help, maybe not.
std::list<AnyType>::iterator it = (std::list<AnyType>::iterator)x.anylist.begin();


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Not sure if I understand your problem fully, but a const_iterator instead of iterator may fix the problem.

/JOlesen
 
X::X(const X &x){
std::list<AnyType>::[red]const_[/red]iterator it=x.anylist.begin();
...
};


-pete
 
Thanx, was a great help

:))


Greetings Andreas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top