Questions about an array template in C++ -


I'm taking a course where we are being offered for some software patterns, one of them is the Iterter pattern , And we are being asked to apply it in C ++, our professor gave us some sample code a few weeks ago and I want to understand a little better than I do as well as I do. First of all, I will post the code:

  template & lt; Class T_, std :: size_t SIZE_ & gt; Class Carry {public: type-tof T_ value_type; Typedef std :: size_t size_type; Type-tof T_ & amp; Context; Type-Touf T_Const & amp; Const_reference; Typedef T_ * pointer; Type-aphed t_cont * cons_ pointer; Type-tof T_ * iterator; Type-tof T_ const * const_iterator; Typedef std :: ptrdiff_t inter_type; Typedef std :: reverse_iterator & lt; Iterator & gt; Reverse_iterator; Typedef std :: reverse_iterator & lt; Const_iterator & gt; Const_reverse_iterator; // data store cost_type data [SIZE_]; Size_type () const {returns SIZE_; } Context operator [] (size_type idx) {return data [idx]; } Const_reference operator [] (size_type idx) const {returns data [idx]; } Reverse_itator Rbijin () {reverse_itator back (end ()); } Reverse_ititor close () {reverse_partter back (start ()); } Const_reverse_iterator rbegin () const {return const_reverse_iterator (end ()); } Const_reverse_iterator closed () const {return const_reverse_iterator (start ()); } Const_reverse_iterator crbegin () const {return const_reverse_iterator (end ()); } Const_reverse_iterator crend ​​() const {return const_reverse_iterator (start ()); } Iterator start () {Return data; } Iterator End () {Return Data + SIZE_; } Const_iterator start () const {returns data; } Const_iterator end () const {returns data + SIZE_; } Const_iterator cbegin () const {returns data; } Const_iterator cend () const {returns data + SIZE_; }};  

In this template our professor has defined a set of type-types, and some of them consisted of both a continuous and continuous version. First of all, I wonder what the purpose of each public member is, and secondly, I wonder what is the purpose of continuous versions in terms of defining a data structure template.

I have also noticed that some of the member works are defined as 'const' and I wonder what its purpose is.

I wonder what the purpose of each public member is.

The class includes the following:

  • Type nickname: Type information that comes out of class for public use.

    • Non-const typedef s is a nickname for the non- const T .
    • Type c is a nickname for type A const T .

    These are typedef s useful because the class user may need more information about the type highlighted by the class < Using code> typedef , he can get it. Here's a good example - consider the situation where we have a template type and we need to reach the built-in iterter type. Using the highlighted nickname, we can access it:

      template & lt; Class container & gt; Zero Example (Container & amp; c) {typename Container :: Eater Beginner = C. Beige (), // ^^^^^^^^^^^^^^^^^^^ end = c.end (); }  

    I wonder what is the purpose of continuous versions.

    Sometimes the user has to type the const type so that the type of information the class provides makes it simple.

I also noticed that some of the member functions are defined as 'const' and I am surprised that its purpose is.

const members are function functions that do not modify the data members of any class.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -