473,544 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1886
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 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?
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 Wikström <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 Wikström
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 Wikström!
>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 Wikström <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 Wikström

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
17272
by: Duane Hebert | last post by:
2 questions: Given a map defined as std::map<int,string> stringmap; //How do you access the data_type (string) via an iterator? std::string spoo("doh");
44
8717
by: jmoy | last post by:
I am a C programmer graduating to C++. As an exercise I wrote a program to count the number of times that different words occur in a text file. Though a hash table might have been a better choice, I chose to use std::map. However, the program runs at less than half the speed of an equivalent program that uses ordinary handcoded binary trees....
14
4037
by: Flzw | last post by:
Well I have a map like this : std::map <string, CObject> ObjectList; I have a function like this : CObject* NewObject( char* Name, CArg* Arg) { std::string key = Name; ObjectList = CObject( Name, Arg);
19
6119
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not found anything). Here's the problem, I have two sets of files, the name of a file contains a number which is unique for each set but it's possible...
3
3697
by: Dan Trowbridge | last post by:
Hi everyone, In my attempt to port code from VS 6.0 to VS.NET I had some code break along the way, mostly due to not adhereing closely to the C++ standard. This may be another instance but I can't think of a good fix, or even why it broke. The problem In one of my CFormView derived classes I have a member variable of the type...
13
1423
by: Peteroid | last post by:
Why does reading a member of a std::map not considered const? For example: class My_Class { int Get_Map_Value( int index ) const // ** error ** not considered const!!! { return m_Map ; // note that m_Map is not changed, only read from }
20
5818
by: Dilip | last post by:
I understand the C++ standard does not talk about threading. My question here is directed more towards what happens when a STL container is used in a certain way. I'd appreciate any thoughts. I re-iterate I don't want to probe into what C++ standard says when I trample some data from multiple threads, I simply want to know if I have...
5
4606
by: Jim Langston | last post by:
Expected output of this program is: 1 -1 -1 -1 Using Microsoft Visual C++ .net 2003 actual output is: 1 4294967295 4294967295
3
2045
by: digz | last post by:
This is a very simplified version of something I am trying to understand. The State object holds the strings and maps , and I pass a reference to State to the process Function which manipulates it based on the tag passed in. I cannot pass the strings/maps in question as references coz .. a) thats redundant, state has everything, it...
0
7370
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7714
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5920
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5305
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3415
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
674
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.