|
-
January 3rd, 2012, 05:38 PM
#1
std::map proper use?
Environment Windows XP Pro, Visual Studio, C++, MFC
After examining some code I use to put data in a map I have become concerned that I may be inserting data improperly. The map for parameters is defined as:
Code:
struct td_parameter_definitions
{
CString name;
unsigned ing tag;
...
};
typedef std::map< td_parameter_key, td_parameter_definitions > td_parameter_map;
The parameter map is within a message structure. The address of the message structure is handed to a method that reads a text file and fills in data. It creates a local pointer to the parameter map and sets fields within the parameter structure as follows:
Code:
Read_parameter_Definitions( st_msg_data *p_msg_data )
{ ...
// make a short hand name for the parameter map
td_parameter_map *p_parm_map = p_msg_data->parameter_map;
parameter_number = <an integer value>;
...
// cs_t1 is filled in by some additional code not shown here.
( *p_parm_map)[parameter_number].name = cs_t1;
// etc
... }
My problem is that I realized that I was not explicitly adding entry [parameter_number] to the map. The code just jumped up and starting putting data in that entry as though it already exists. I am finding that rather worrying.
Since the map is defined as a map of structures and not defined as a map of pointers, does the simple act of referencing entry [1] (for example) create that entry. If so, then is it OK for the code to proceed to set various fields of that entry.
Is that a back door to creating an entry in a map that I should not use?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|