This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: STL defect?
- To: nbecker <nbecker at fred dot net>
- Subject: Re: STL defect?
- From: Thomas Kunert <kunert at physik dot tu-dresden dot de>
- Date: Wed, 02 Sep 1998 11:38:50 +0200
- CC: egcs at cygnus dot com
- Organization: TU Dresden
- References: <E0zDsev-0006Tf-00@hns.com>
nbecker wrote:
>
> This small test program demonstrates either a defect in STL design or
> in egcs implementation.
>
> -----------------
> #include <vector>
> #include <deque>
>
> main () {
> vector<double> V;
> deque<double> D;
> vector<double>::iterator I;
> deque<double>::iterator J;
> double* p1 = J.operator->();
> double* p2 = I.operator->();
> }
>
> ---------------
> g++ -c Test.cc
> Test.cc: In function `int main()':
> Test.cc:10: request for member `operator ->' in `I', which is of non-aggregate type `double *'
>
> The problem is that the builtin pointer types don't implement operator->, so
> operator-> won't work for vector, whose underlying representation of
> an iterator is a pointer. But STL says that iterators should have an
> operator->.
What do you mean by `STL says' ?
The standard doesn't require that and, IIRC, has never done.
It just says, that `I->x' is equivalent to `(*I).x' *if the latter is
well-defined*.
You can rewrite the above expression:
double* p1 = &(*J);
double* p2 = &(*I);
--
Thomas Kunert