reference operator*() { return *_ptr; } //解引用操作
array_iterator<T, N>&operator++() //前置递增
{
++**this; //增加_ptr,
//当把上面那句改为 ++_ptr后就能实现 这两者的区别是什么?
return *this;
}
array_iterator<T, N> operator++(int) //后置递增
{
array_iterator<T, N> tmp = *this; //返回量
++*this;
return tmp;
}
当把++**this;改为 ++_ptr就能实现,这两者有什么区别?
(_ptr是类里的一个成员,为指针类型 T*)
++*this
== ++(this->operator*())
== ++*(this->_ptr)
== ++*_ptr
++*_ptr and ++_ptr are obviously different, so of course your code cannot realize your wish.
reference operator() { return _ptr; } //The dereference operation
the appeal statement returns the value pointed to by ptr,
and this gets the class, which then When calling the operator above, you get the value pointed to by the pointer, so the value pointed to by the pointer is actually modified instead of the value of the pointer.