Re: What is wrong with reference into std::map?
"Phlip" <phlipcpp@yahoo.com> wrote in message
news:yTK9g.6118$fb2.1409@newssvr27.news.prodigy.net...
Jim Langston wrote:
it = MyMap.insert( MyMap.end(), std::make_pair< unsigned int,
std::string >( ID, std::string() ) );
Could you break up all these long lines, pleeeeze? Start with
typedef std::make_pair< unsigned int, std::string > mapType;
then use that everywhere you copied in that whole gizmo.
Yeah, well, the problem is I'm using a number of maps, 4, and I would have
to do that for every map since they're different pair types. By the time I
typedefed the maps, the iterators and the make pairs that's 12 different
things I have to remember what is what.
It's just easier for me to type them in so I don't have to keep going back
and seeing what they are.
Hmm.. so how do you assign a reference that has already been initialized?
int& MyRef = int1;
Who do I do to get MyRef to point to int2 now? Or can I?
You can't reseat a reference. That's a feature. You said "point to", which
betrays you think of a reference as a kind of pointer. It's really another
name for something; an alias.
Will a map let you use iterators? Some containers invalidate their
iterators after an insert, but I can't think of a technical reason for a
binary tree to do that, and maps generally implement as binary trees.
Well, I'm only using the reference after the insert to set the data, then I
don't use it anymore. The reference may be invalidated after another
insert, I'm not sure.
Well, I came across this problem and figured out that by putting brackets
around the whole thing the problem went away, I just wanted to know what the
problem was before I converted it into a function.
I'm goign to have to remember that you can't reset a reference. Dang, I
hope they add that to the language. Even if it takes another keyword.
std::reseat MyRef = int2;
MyRef<std::reseat> = int2;
std::reseat<int&>( MyRef ) = int2;
any format
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!