470,571 Members | 2,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,571 developers. It's quick & easy.

behavior of a std::map I don't understand...

I'm using Visual Studio 2005, but i don't think that's (primarily)
where I've gone wrong.

I was experimenting, trying, by the way, to move into writing my own
iterator so that I can learn, ultimately, to write templates:
std::map< int, char [12] cm;
char str0[12] = {'f','i','r','s','t',' ','t','e','x','t','\0'};

cm[0] = str0;

The compiler says about that assignment,
left operand must be l-value

What does this mean, what's happened here?

It compiles without error when the value arg in the map is instead a
char or a char *.
std::map< int, char *cm;

Thanks for your help and knowledge.

Harold
Nov 15 '07 #1
9 1730
Heck wrote:
I'm using Visual Studio 2005, but i don't think that's (primarily)
where I've gone wrong.

I was experimenting, trying, by the way, to move into writing my own
iterator so that I can learn, ultimately, to write templates:
std::map< int, char [12] cm;
char str0[12] = {'f','i','r','s','t',' ','t','e','x','t','\0'};

cm[0] = str0;

The compiler says about that assignment,
left operand must be l-value

What does this mean, what's happened here?

It compiles without error when the value arg in the map is instead a
char or a char *.
std::map< int, char *cm;
Arrays are not assignable.
Nov 15 '07 #2
On 2007-11-16 00:12, Heck wrote:
I'm using Visual Studio 2005, but i don't think that's (primarily)
where I've gone wrong.

I was experimenting, trying, by the way, to move into writing my own
iterator so that I can learn, ultimately, to write templates:
std::map< int, char [12] cm;
char str0[12] = {'f','i','r','s','t',' ','t','e','x','t','\0'};

cm[0] = str0;

The compiler says about that assignment,
left operand must be l-value

What does this mean, what's happened here?

It compiles without error when the value arg in the map is instead a
char or a char *.
std::map< int, char *cm;
You can not store an array in a map (or any other collection for that
matter).

--
Erik Wikström
Nov 16 '07 #3
Heck wrote:
char str0[12] = {'f','i','r','s','t',' ','t','e','x','t','\0'};
Btw, you can save typing by simply writing:

char str0[12] = "first text";
Nov 16 '07 #4
LR
Erik Wikström wrote:
You can not store an array in a map (or any other collection for that
matter).
Sorry, I don't understand what you mean by collection. Could you please
expand on that?

TIA

LR

Nov 16 '07 #5
LR wrote:
Erik Wikstrm wrote:
>You can not store an array in a map (or any other collection for that
matter).

Sorry, I don't understand what you mean by collection. Could you
please expand on that?
Erik will hopefully give his POV, but AFAICT, Erik meant any standard
container by "any other collection".

Arrays do not satisfy the requirements for the contained items. The
main two are Assignable and Copy-constructible. Arrays are neither.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 16 '07 #6
On Nov 15, 11:41 pm, Erik Wikstrm <Erik-wikst...@telia.comwrote:
On 2007-11-16 00:12, Heck wrote:
I'm using Visual Studio 2005, but i don't think that's (primarily)
where I've gone wrong.
I was experimenting, trying, by the way, to move into writing my own
iterator so that I can learn, ultimately, to write templates:
std::map< int, char [12] cm;
char str0[12] = {'f','i','r','s','t',' ','t','e','x','t','\0'};
cm[0] = str0;
The compiler says about that assignment,
left operand must be l-value
What does this mean, what's happened here?
It compiles without error when the value arg in the map is instead a
char or a char *.
std::map< int, char *cm;

You can not store an array in a map (or any other collection for that
matter).

--
Erik Wikstrm
Wrap your array in a class and define the assignment operator

Jeff

http://theschmitzer.blogspot.com
Nov 16 '07 #7
On 2007-11-16 16:58, LR wrote:
Erik Wikström wrote:
>You can not store an array in a map (or any other collection for that
matter).

Sorry, I don't understand what you mean by collection. Could you please
expand on that?
Sorry about that, I have been programming to much VBA (ugh!) lately.
Just like Victor guessed I meant a standard container.

--
Erik Wikström
Nov 16 '07 #8
Erik Wikstrm!
>On 2007-11-16 00:12, Heck wrote:
>I'm using Visual Studio 2005, but i don't think that's (primarily)
where I've gone wrong.

I was experimenting, trying, by the way, to move into writing my own
iterator so that I can learn, ultimately, to write templates:
std::map< int, char [12] cm;
char str0[12] = {'f','i','r','s','t',' ','t','e','x','t','\0'};

cm[0] = str0;

The compiler says about that assignment,
left operand must be l-value

What does this mean, what's happened here?

It compiles without error when the value arg in the map is instead a
char or a char *.
std::map< int, char *cm;

You can not store an array in a map (or any other collection for that
matter).
OK, thanks (and thank you all). Is your answer consistent with the
compiler telling me the map element, in this case, cm[0], is not an
l-value? It is an l-value, isn't it? It's the array that's not an
r-value, right?
Nov 18 '07 #9
je***************@gmail.com!
>On Nov 15, 11:41 pm, Erik Wikstrm <Erik-wikst...@telia.comwrote:
>On 2007-11-16 00:12, Heck wrote:
I'm using Visual Studio 2005, but i don't think that's (primarily)
where I've gone wrong.
I was experimenting, trying, by the way, to move into writing my own
iterator so that I can learn, ultimately, to write templates:
std::map< int, char [12] cm;
char str0[12] = {'f','i','r','s','t',' ','t','e','x','t','\0'};
cm[0] = str0;
The compiler says about that assignment,
left operand must be l-value
What does this mean, what's happened here?
It compiles without error when the value arg in the map is instead a
char or a char *.
std::map< int, char *cm;

You can not store an array in a map (or any other collection for that
matter).

--
Erik Wikstrm

Wrap your array in a class and define the assignment operator
I'm getting to that, yes. Thanks very much.
Nov 18 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by Duane Hebert | last post: by
44 posts views Thread by jmoy | last post: by
14 posts views Thread by Flzw | last post: by
19 posts views Thread by Erik Wikstrm | last post: by
5 posts views Thread by Jim Langston | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.