Ayanami
칼리
- Reaction score
- 288
Wanted to know how Inheritance exactly works in JASS. Let's say you have struct Parent and struct Child, I understand that the Child inherits instance members and methods only, right?
I'm confused about the constructor part. If you call [ljass]local Child c = Child.create()[/ljass], this calls Parent's [ljass].create[/ljass] method? Would that mean the variable c holds Parent's instance or Child's instance? I would like to know how exactly the constructor works for a Child & Parent.
Another question:
If the above is legal, let's say I have a new scenario: struct Parent, struct Child1, struct Child2.
And for the above scenario, would calling [ljass]p.print()[/ljass] result in an error?
Thanks.
I'm confused about the constructor part. If you call [ljass]local Child c = Child.create()[/ljass], this calls Parent's [ljass].create[/ljass] method? Would that mean the variable c holds Parent's instance or Child's instance? I would like to know how exactly the constructor works for a Child & Parent.
Another question:
JASS:
If the above is legal, let's say I have a new scenario: struct Parent, struct Child1, struct Child2.
JASS:
struct Parent
method print takes nothing returns nothing
call BJDebugMsg("Hi")
endmethod
endstruct
struct Child1 extends Parent
endstruct
struct Child2 extends Parent
endstruct
function Test takes nothing returns nothing
local Parent p
if GetRandomInt(0, 1) == 0 then
set p = Child1.create()
else
set p = Child2.create()
endif
// anyway to check if p holds an instance of Child1 or Child2?
endfunction
And for the above scenario, would calling [ljass]p.print()[/ljass] result in an error?
Thanks.