c++ - What is the difference between STL containers iterator and C pointer iterator -


I am writing a reverse iterator as part of my own custom vector class. So far what I have written is the following.

  class MyVector {public: typedef T value_type; Typedef value_type * indicator; Typefifth console value_type * const_pointer; Typedef value_type & amp; Context; TypefifiControl viral_type & amp; Const_reference; Typedf Pointer Iterator; Type-tof config pointer controller; Typedef size_t size_type; Square reverse_title {Private: Iterator Iter; Public: Inline Reverse_title (Iterator A = 0): Iter (A) {} Inline Reverse_itator (Const Rivers_title and Reovitter): IAR (rev_iter.iter) {} Inline Reverse_Iterator & amp; Operator ++ () {--iter; Return * This; } // and the rest of the other operators}}; Inline Iterator Start (Zero) {Return (Iterator data_array); } Inline easter end and (zero) {return ((ifter) data_arra + number_of_edments); } Inline reverse_itator rbb (empty) {return end () - 1;} inline reverse_ititor shutdown (zero) {returns start () - 1;} // function for myequator class}; // myvector end of the class   

The above square iterator is just the C-style indicator and the reverse_iterator class is. That's why when I

  main () {myVector & lt; Int & gt; I; MyVector & lt; Int & gt; :: reverse_iterator rit = i.begin (); }   

My reverse_titler has been started with the Start () function and the code is compiled and running. But it does not happen in STL's iterator and reverse_itator. They prevent such initialization as the reverse_iatorate does not allow itself to start with the start () function, it must be started with rbegin ()

So what should I do to avoid such a start? Should I write a different Iterator as it is in STL and I think it is not possible to write it .. Please give me some solution ...

Iterators

The most obvious: moving each Iterator in the opposite direction while increasing.

Less obvious: The beginning of () No is the end of a reverse itater. must start () - 1 Remember that end () represents "one-past-end", because C ++ categories are half open, that is [Start, end]. If you swap only start () and end () in your reverse iterator, then your reverse itater will have a range (beginning, end).

In other words, there is one reason that STL containers have both start () and end () and rbegin () And rend () , even if the iterator and reverse indicator are compatible in some ways.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -