Original Post
First of all, I don't know what this is called, so I'm struggling to find info on it. :) I use code similar to below in Delphi to create a new instance of an object, without knowing the actual type of the object. I need to know if there's a way to do it in C++.. In this code, the OtherObj could be any one of the 2 derived classes. Any help would be really appreciated. Even if someone could tell me what it's called? :p
interface
type
TbaseObjClass = class of TbaseObj;
TbaseObj = class;
TDerivedObj1 = class(TbaseObj);
TDerivedObj2 = class(TbaseObj);
implementation
var
baseObjClass:TObjClass;
Obj:TbaseObj;
begin
baseObjClass:=TbaseObjClass(OtherObj.ClassType);
Obj:=baseObjClass.create;
end;