Topic: Inheriting vector::iterator produce error
Author: "Itay Sali" <itays@ncc.co.il>
Date: 2000/06/06 Raw View
Hi,
I am using VC 6.0 on NT machine.
I need to inherit (public inheritance) of vector iterator. The class which
inherit it is a node in a list.
This is redesign of hug application. The inheritance cause the following
error:
lclist.h(159) : error C2516: 'iterator' : is not a legal base class
d:\program files\microsoft visual studio\vc98\include\vector(31) :
see declaration of 'iterator'
I examine the vector declaration : typedef _Tptr iterator;
It's not possible to inherit typdef.
Trying to inherit _Tptr pointed the next typedef of _Tptr A::pointer.
Inheriting A::pointer cause error :
lclist.h(155) : error C2653: 'A' : is not a class or namespace name
lclist.h(156) : error C2504: 'pointer' : base class undefined
Is there any trick to inherit iterator or its a must to use it as a member.
Thanks
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Matt Austern <austern@sgi.com>
Date: 2000/06/06 Raw View
"Itay Sali" <itays@ncc.co.il> writes:
> Hi,
>
> I am using VC 6.0 on NT machine.
>
> I need to inherit (public inheritance) of vector iterator. The class which
> inherit it is a node in a list.
> This is redesign of hug application. The inheritance cause the following
> error:
>
> lclist.h(159) : error C2516: 'iterator' : is not a legal base class
> d:\program files\microsoft visual studio\vc98\include\vector(31) :
> see declaration of 'iterator'
>
> I examine the vector declaration : typedef _Tptr iterator;
>
> It's not possible to inherit typdef.
>
> Trying to inherit _Tptr pointed the next typedef of _Tptr A::pointer.
> Inheriting A::pointer cause error :
>
> lclist.h(155) : error C2653: 'A' : is not a class or namespace name
> lclist.h(156) : error C2504: 'pointer' : base class undefined
>
> Is there any trick to inherit iterator or its a must to use it as a member.
There's no guarantee that vector<T>::iterator is a class. The
standard permits it to be a typedef for T*, as it is in the
implementation you're using. (And in several other implementations.)
You can't inherit from pointers, only from classes.
There are some implementations where vector<T>::iterator is a class,
and inheriting from vector<T>::iterator will work on such an
implementation. Your code won't be portable, though.
As a general piece of advice, I'd recommend that you not try to
inherit from STL iterator classes; you're trying to use the library in
a way that it was not designed for. There's probably a better way to
do whatever you're doing.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]