[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-atl
Subject:    Re: STL
From:       Gilles POIROT <GPOIROT () CARTESIS ! COM>
Date:       2001-05-17 8:49:49
[Download RAW message or body]


Hi

You need a const_iterator whenever you want to iterate through a const
container
e.g.

void myfunction(const std::list<mytype>& mylist_readonly)
{
        // Causes an error at compile time 
        std::list<mylist>::iterator bad_it = mylist_readonly.begin();

        // This time is fine	
        std::list<mylist>::const_iterator good_it= mylist_readonly.begin(); 
}


Gilles


-----Message d'origine-----
De: Phil Beck [mailto:phil@EF-X.COM]
Date: jeudi 17 mai 2001 10:25
À: ATL@DISCUSS.MICROSOFT.COM
Objet: OT: STL


Just a quickie.

When iterating through a container such as :-

std::list<mytype>

why do I sometimes need a const_iterator instead of just an iterator ?
Using an iterator sometimes give me the compile error :-

binary '=' no operator defined which takes a right hand operand of type
std::list<class mytype,class std::allocator<class mytype> >::iterator

Phil.

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:ATL-signoff-request@DISCUSS.MICROSOFT.COM

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:ATL-signoff-request@DISCUSS.MICROSOFT.COM

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic