由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++ pointers are iterators, why?
相关主题
c++ interview: iterator 和 pointer区别?C++ Q90 - Q92 (转载)
deque的pointer和reference是怎么回事?大家觉得C++复杂在哪里?
一个C++的概念问题C++: &*var是啥意思?
这个问题怎么答?Use std::swap to exchange pointers and iterators
这段code有啥问题?Pointer to iterator?
C++ 菜鸟问一个关于template 的问题。请教 C++ std::list iterator 对 template class pointer 的应用问题
one more interview questionstl的interator是一种smart pointer吗
can you insert several function pointers into a queue ?弱问c++ iterator 和 pointer区别
相关话题的讨论汇总
话题: iterators话题: pointers话题: iterator话题: pointer话题: c++
进入Programming版参与讨论
1 (共1页)
r****t
发帖数: 10904
1
在本版前面看到师傅们说过,不过当时就有疑问:
为啥 pointers are iterators?
只是因为 iterator objects support pointers arithmetic 就这么说么?(比如
sequential containers 可以用一对 pointer 来初始化,这个是不是用的 overload
ctor 来实现的?)总觉得这样逻辑有点不通,倒像是 duck typing 的逻辑了。
还是有啥别的意思在里面?
t****t
发帖数: 6806
2
short answer: iterators are generalized pointers. so pointers, by definition
, are iterators.
long answer: there is no iterator "type" or pointer "type". iterator and
pointer are CONCEPTs, which are classes of types (that satisfy some
condition). pointer satisfy all the requirement of iterator so pointer is
iterator.
for implementation, anything suuport "iterator" (or some subclasses of
iterators) must be implemented with template (template is a set of
overloaded functions, so you are right, it is by "overload ctor"), since
iterator is not a single type.

【在 r****t 的大作中提到】
: 在本版前面看到师傅们说过,不过当时就有疑问:
: 为啥 pointers are iterators?
: 只是因为 iterator objects support pointers arithmetic 就这么说么?(比如
: sequential containers 可以用一对 pointer 来初始化,这个是不是用的 overload
: ctor 来实现的?)总觉得这样逻辑有点不通,倒像是 duck typing 的逻辑了。
: 还是有啥别的意思在里面?

1 (共1页)
进入Programming版参与讨论
相关主题
弱问c++ iterator 和 pointer区别这段code有啥问题?
树的前序遍历C++ 菜鸟问一个关于template 的问题。
关于inserterone more interview question
c++ template question:can you insert several function pointers into a queue ?
c++ interview: iterator 和 pointer区别?C++ Q90 - Q92 (转载)
deque的pointer和reference是怎么回事?大家觉得C++复杂在哪里?
一个C++的概念问题C++: &*var是啥意思?
这个问题怎么答?Use std::swap to exchange pointers and iterators
相关话题的讨论汇总
话题: iterators话题: pointers话题: iterator话题: pointer话题: c++