Q:

How to insert an object to a map structure by a certain field?

i have an object - Employee, and i want to know how to insert this object to a map structure sorted by char* lastName field. Thanx.
My map need to contain pointers to Employee objects not the objects themselves. the key is the last name of the employee, the map need to be sorted by the employees last name, should i use multimap?

A:

So you've got an std::map with a custom comparator function (you've overloaded the less than operator) and you want to insert objects so that they're in the right order?
myMap.insert( make_pair( myKey, myEmployee ) );

where myKey is the key to your map.  However, from the sound of your question it actually sounds like you're using the object as it's own key.  In that case, just use std::set and
mySet.insert( myEmployee );

I'd also suggest that you not use char* as a means to store lastName and prefer the std::string.
EDIT:
Following the comments down below, are you having to be able to pass in a const char* into another function?  If so, still use string as it has a nice method .c_str() specifically for legacy compatibility.  It can be used as so:
void stuffHappens(const char* _input){
    //magic happens in here
}

stuffHappens( myString.c_str() );

and voila, you're much safer!

