I’ve some little question about STL iterator implementation.
- why iterator defining as a struct but not as class?
- what is the main reason?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is defined in the standard, 24.2 which describes the
<iterator>header, which arestruct. This choice was probably made because iterators provide access to container elements and making themclasswould be useless, the only difference being thatclasshasprivateaccess level by default, whereasstructhaspublicaccess level.So there were 2 choices if declaring iterators
classinstead ofstruct:public, which is useless since the same effect can be obtained by making it directlystruct.