Taking a copy of an object
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Tue Aug 8 07:36:17 PDT 2006
kris wrote:
>
> BTW: one concern I'd have with a root-Object dup() method is the need to
> cast the returned instance. Presumeably a more specific compiler
> implementation (of object.dup) would sidestep that need for casting?
There is no need for casting. Since D supports covariant return types,
the overriding methods can return their specific types:
class Foo {
Foo Clone() {
return new Foo();
}
}
class FooBar : Foo {
override FooBar Clone() {
return new FooBar();
}
}
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list