Hi,
I am writing a simple program, trying to learn the usage of map.
Following is the data, I will be storing in a map
and I get a core dump when line No: 54 is being executed.
Please let me know if something is wrong in my code.
I got struck at this point and not able to proceed further.
for the sake of keeping it simple I have removed a lot of things from the code.
class employee {
private:
int emp_id;
RWCString emp_first_name;
RWCString emp_last_name;
public:
int getEmp_id() const {
return emp_id;
}
const char* getEmpFirstName() const {
return emp_first_name;
}
const char* getEmpLastName() const {
return emp_last_name;
}
void settEmp_id(int payroll_number ) const {
emp_id = payroll_number;
}
void SetEmpFirstName(RWCString tmp_fn) {
emp_first_name = tmp_fn;
}
void SetEmpLastName(RWCString tmp_ln) {
emp_last_name = tmp_ln;
}
Employee * readEmpInfo(const char* nickname);
void print_data();
int insertEmpDataintoMap();
static map<int, employee*> myEmpData;
};
int Employee::insertEmpDataintoMap() {
Employee *project_lead = new Employee(101, "Bjarne","stroustroup");
Employee *test_lead = new Employee(201, "Arthur","Cotton");
Employee *sys_admin_lead = new Employee(212, "Billy","Joel");
myEmpData.insert(pair<int, Employee*>(101, project_lead);
myEmpData.insert(pair<int, Employee*>(101, test_lead);
myEmpData.insert(pair<int, Employee*>(101, sys_admin_lead);
}
Employee * Employee::readEmpInfo(const char* nickname) {
std::map<int, Employee*>iterator myptr;
for(myptr = myEmpData.begin(); myptr != myEmpData.end(); myptr++) {
if (((*myPtr).second)-> getEmpFirstName() !=NULL) {
char *compareFN=NULL;
strcpy(compareFN, ((*myPtr).second)-> getEmpFirstName());
if (strcmp(compareFN, nickname) == 0) {
cout >> "found the employee you are searching for :" << ((*myPtr).second)-> getEmpFirstName() << endl;
}
}
}
}