Iterators in C++ (stl) vs Java, is there a conceptual difference?

前端 未结 9 1005
夕颜
夕颜 2020-12-13 09:30

I\'m returning to c++ after being away for a bit and trying to dust off the old melon.

In Java Iterator is an interface to a container having methods: hasNext

9条回答
  •  没有蜡笔的小新
    2020-12-13 09:53

    C++ library (the part formerly known as STL) iterators are designed to be compatible with pointers. Java, without pointer arithmetic, had the freedom to be more programmer-friendly.

    In C++ you end up having to use a pair of iterators. In Java you either use an iterator or a collection. Iterators are supposed to be the glue between algorithm and data structure. Code written for 1.5+ rarely need mention iterators, unless it is implementing a particular algorithm or data structure (which the vary majority of programmers have no need to do). As Java goes for dynamic polymorphism subsets and the like are much easier to handle.

提交回复
热议问题