Re: Class defined Inside a Class
Rolf Magnus wrote:
anon wrote:
To pick up the iterator example, how would you suggest to do that?
Whats wrong with it?
I'm thinking e.g. about the iterator for std::vector, which is defined within
std::vector, so it's then std::vector::iterator. How would you name the
iterator type belonging to std::vector instead? And how would that
additional namepace come into play?
This is from the gcc "vector" header:
*************************************************************
namespace __gnu_debug_def
{
template<typename _Tp,
typename _Allocator = std::allocator<_Tp> >
class vector
: public _GLIBCXX_STD::vector<_Tp, _Allocator>,
public __gnu_debug::_Safe_sequence<vector<_Tp, _Allocator> >
{
// some stuff
public:
typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,vector>
iterator;
typedef __gnu_debug::_Safe_iterator<typename
_Base::const_iterator,vector>
const_iterator;
*************************************************************
So, why are you saying the iterator is defined within the vector class?
Is this ok :
http://www.cplusplus.com/reference/misc/iterator/iterator.html
?
Well, that's an iterator for simple arrays, but usually, an iterator type
belongs to a specific class.
Do you have an example? Explaining how the iterator is defined within
the vector class would do :)
Btw: The example on that page seems to contain an error:
myiterator& operator++() {++p;return *this;}
myiterator& operator++(int) {p++;return *this;}
That doesn't look right. The second operator++ is supposed to return the
previous value of *this, not the new one.
Correct.