If I have two objects (Intern and Manager) derived from an Employee class, could I create a function that would return a pointer to a new instance of one of the two derived objects by passing the type to the function. So, could I do something like this (I know this gives me an error, the example is just for clarity of what I'm trying to do):
Employee* createEmployee(typename T){
return ( new T() ) ;
}
So, if I wanted to create a new Manager, I would say createEmployee(Manager)
, and I would get a pointer to a new Manager object.