In other laungages (C++, Java) the first instruction within a constructor is calling a superclass constructor; if not done explicitly, an implicit call to an empty constructor is provided. In AHK this doesn't seem to be the case. Following example
Code: Select all
mySubObj := new mySubclass()
fileAppend, % mySubObj.var " , " mySubObj.subVar "`n", *
class myClass {
var := ""
__New() {
this.var := "Some default value"
}
}
class mySubclass extends myClass {
subVar := ""
__New() {
; base.__New()
this.subVar := "Another default value"
}
}
> , Another default value
the value of subVar; the var field remains empty, base.__New() is not implicitly called. If i would remove the commenting out in the above code, the output would be
> Some default value , Another default value
The doc states
From my observation, it isn't, if not done manually. On the other hand, the base object is not empty, it is still created, even if base.__New() is not called. Quite confusing.Whenever a derived object is created with the new keyword ..., the __New method defined by its base object is called.
So ... well, what exactly is going on, when chaining constructors and creating derived objets with the new keyword ?