erg/examples/init_del.er
2024-03-03 20:00:06 +09:00

28 lines
449 B
Python

i = !0
@Inheritable
C = Class()
C::[<: Self]
__init__! self =
print! "initialize C:", self
i.inc!()
__del__! self =
print! "delete C:", self
i.dec!()
p!() =
c = C.new()
assert i == 1
print! c
p!()
assert i == 0
D = Inherit C, Additional := { x = Int }
D::[<: Self]
@Override
__init__! self =
C::__init__! self
print! "initialize D:", self, self::x
_ = D.new { x = 1 }