Interview Question
Solutions ArchitectsCountry: United States
this is one way of using it
class Class {
public:
static class* forName (const string* name) {
if (strcmp(*name,"CLASS") {
return new Class;
}
else(strcmp(*name,"DERIVED"){ //in case a derived obj is to be created
return new Derived;
}
}
};
this type of obj creation is mainly needed when we create an obj during run time depending on the user input. hope this helps.
Insufficient details in the question.
- Anonymous March 27, 2013What is the type that function is supposed to return? void *?
How would the caller know what to cast it to, in order to actually use it?
Do you want people to design a COM (Microsoft's solution for this type of a problem) like system?