Article View: att.lang.c++
Article #119Can you assign a value via an iterator?
From: Tim Mavers
Date: Mon, 21 Jun 1999 00:00
Date: Mon, 21 Jun 1999 00:00
35 lines
1530 bytes
1530 bytes
I can't figure out why this code doesn't work. I searched through the
include files for map and xtree but couldn't figure out what they were
doing.
I am basically assigning a new value to all my entries in a map via an
iterator:
--cut--
typedef std::map<int, MyClass*, std::less<long> > MyContainer;
typedef MyContainer::iterator MyIterator;
MyContainer myContainer;
void OrderSequentially()
{
int key = 0;
MyIterator iter = myContainer.begin();
while(myContainer.end() != iter)
{
(*iter).first = key++;
iter++;
}
}
--cut--
The compiler (VC6 sp3) complains with "error C2166: l-value specifies const
object" and points to the line:
(*iter).first = key++;
Why is this? I am not using a const iterator.
Thanks
Technical Details
Message-ID:
<Klwb3.41580$YO1.561521@newscene.newscene.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,eda170c74aea3653,start X-Google-Attributes: gid109fba,public X-Google-Thread: 108b44,eda170c74aea3653,start X-Google-Attributes: gid108b44,public X-Google-Thread: 10d4ba,eda170c74aea3653,start X-Google-Attributes: gid10d4ba,public From: "Tim Mavers" <webview@hotmail.com> Subject: Can you assign a value via an iterator? Date: 1999/06/21 Message-ID: <Klwb3.41580$YO1.561521@newscene.newscene.com> X-Deja-AN: 492217717 Organization: Newscene Public Access Usenet News Service (http://www.newscene.com/) X-MSMail-Priority: Normal X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Newsgroups: att.lang.c++,comp.lang.c++,comp.sys.lang.c++