Topic: typedefs for inherited types
Author: Stefan Kuhlins <kuhlins@wifo.uni-mannheim.de>
Date: 1997/12/09 Raw View
The three types difference_type, reference and pointer are defined
in the base-class iterator. Why do we need typedefs for inherited types?
24.4.1.1 Template class reverse_iterator [lib.reverse.iterator]
template <class Iterator>
class reverse_iterator : public
iterator<typename iterator_traits<Iterator>::iterator_category,
typename iterator_traits<Iterator>::value_type,
typename iterator_traits<Iterator>::difference_type,
typename iterator_traits<Iterator>::pointer,
typename iterator_traits<Iterator>::reference> {
public:
typedef typename iterator_traits<Iterator>::difference_type
difference_type;
typedef typename iterator_traits<Iterator>::reference
reference;
typedef typename iterator_traits<Iterator>::pointer
pointer;
// ...
};
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Colin Rafferty <craffert@ml.com>
Date: 1997/12/10 Raw View
Stefan Kuhlins writes:
> The three types difference_type, reference and pointer are defined
> in the base-class iterator. Why do we need typedefs for inherited types?
Because the typedefs are different from the inherited type. In general,
the typedef is gotten from `iterator_traits', while the class inherits
from `iterator'.
For example, the inherited type of `pointer' is:
iterator<typename iterator_traits<Iterator>::iterator_category,
typename iterator_traits<Iterator>::value_type,
typename iterator_traits<Iterator>::difference_type,
typename iterator_traits<Iterator>::pointer,
typename iterator_traits<Iterator>::reference>::pointer
The typedef of `pointer' is:
iterator_traits<Iterator>::pointer
> 24.4.1.1 Template class reverse_iterator [lib.reverse.iterator]
> template <class Iterator>
> class reverse_iterator : public
> iterator<typename iterator_traits<Iterator>::iterator_category,
> typename iterator_traits<Iterator>::value_type,
> typename iterator_traits<Iterator>::difference_type,
> typename iterator_traits<Iterator>::pointer,
> typename iterator_traits<Iterator>::reference> {
> public:
> typedef typename iterator_traits<Iterator>::difference_type
> difference_type;
> typedef typename iterator_traits<Iterator>::reference
> reference;
> typedef typename iterator_traits<Iterator>::pointer
> pointer;
> // ...
> };
--
Colin
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]