On Thu, 13 Jan 2000, Martin v. Loewis wrote:
> > I think I can use statement like this:
> >
> > 1. (*i).x+=1.0;
> >
> > or
> >
> > 2. MyObject& t=*i;
> >
> > But the g++ compiler always think "i" is a const_iterator,
> > it give error for 1, and warning for 2.
> >
> > Who can tell me why?
>
> If i is a const_iterator, the object referred-to by the iterator is
> const, and you must not modify it. If the object is const, then (*i).x
> is also const, and you cannot assign to it. Also, *i is of type
> "MyObject const &"; you should not assign this to a variable of type
> "MyObject&", as this also gives you a way to modify *i, even though *i
> is const.
i is not a const_iterator, just an iterator.
Sincerely Yours,
FengLou Mao
*******************************
ADD:Mr. FengLou Mao
Institute of Physical Chemistry
Peking University
BeiJing
P.R.China
Tel:86-10-62756833
Fax:86-10-62751725