🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Tim Mavers Mon, 21 Jun 1999 00:00
Can you assign a value via an iterator?
#119
Author: Tim Mavers
Date: Mon, 21 Jun 1999 00:00
35 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads