At 10:26 AM +0100 8/22/02, Steve Thomas wrote:
Since class2 is a subclass, the two are type-compatible, so syntactically
and semantically everything is fine. However, I can't find a way of
instantiating a new object of the same subclass as the current object, from
code within the superclass.
You can't. You need to make a NewSameType method, which is
overridden by each subclass to return a new instance of that class.
I can think of a workaround, which uses a virtual method NewObject(), which
returns a new instance, which is overridden in each subclass to instantiate
a member of that subclass.
I see we're on the same wavelength!
Cheers,
- Joe
--
,------------------------------------------------------------------.
| Joseph J. Strout REAL Software, Inc. |
| joe at realsoftware dot com http://www.realsoftware.com |
`------------------------------------------------------------------'
|