Link to home
Start Free TrialLog in
Avatar of bhuey_ling
bhuey_ling

asked on

Function Pointer

Hi,

I have a piece of code below:

//base class Employee, derive class manager, engineer, clerk
vector<Employee*>  employee_vec;

if ( strcmp( input, "manager") == 0) {
    employee_vec.push_back(new manager());
}
else if ( strcmp( input, "engineer") == 0) {
    employee_vec.push_back(new enginner());
}
else if ( strcmp( input, "clerk") == 0) {
    employee_vec.push_back(new clerk());
}

 (employee_vec[employee_vec.size() -1]) -> setSalary();
 (employee_vec[employee_vec.size() -1]) -> setJobcode();


1. I'm looking that is there any better method/new technique  that just use one/two line to replace the if/else loop?
2. Or this if/else loop is the simple yet most efficient way to do it?
3. Basically, would like to learn any new techique or more efficient way same purpose

thanks.
Avatar of bhuey_ling
bhuey_ling

ASKER

will function pointer is one of solution?  
ASKER CERTIFIED SOLUTION
Avatar of Jase-Coder
Jase-Coder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why function pointers is no needed in this place? Is function pointer use for other purpose?

thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial