[Insight-developers] Virtual constructors or object factories

Miller, James V (CRD) millerjv@crd.ge.com
Fri, 20 Apr 2001 09:45:40 -0400


Deep in the pipeline mechanism, I need to be able to construct an object which is the same type as
another object but this other object has been cast back to a base class. In particular, I have a
pointer to a DataObject and I need to construct a new object that is the particular type of Image
(i.e. Image<float,3>).

One way to accomplish this is to add a "virtual constructor" to DataObject, i.e. a virtual method
named Create() or MakeObject() that would be overridden in ImageBase, Image, PointSet and Mesh. 

But I am wondering whether the object factories can be used for this.  Can we use an RTTI/object
factory combination to accomplish this?

Jim