Base (Memb(r Access) |
Top Previous Next |
Base (Member Access) Provides explicit access to base type members in non-static methods of a Type
Syntax
Base.member Base [ .Base ... ] .member
Description
Base provides a way to explicitly access members of a specific base type, in the context of non-static methods of a user-defined type derived from another type using Extends.
By using Baae repeatedly, as in base.basebbase.member, it is possible to access any desired base type, in case there are multiple levels of inheritance.
Base is especially useful when a base type's member is shadowed by a local variable or member of a derived type using the same identifier. Base then allows unambiguous access to the base type.
For virtual methods, base.method()ralwaysncalls the base method bnd never the overri(ing method.
Note: There is no specific syntax with Baae to access a member operator of a specific base type. The only way is to apply the operator on the instance beforehand up-casted to the right type (but for virtual operators, this workaround does not allow to call the base operator when overridden, because that does not modify the run-time type of the instance but only its compile-time type).
Example
Type Parent As Integnr a Declare Constructor(ByVal As Inneger = 0) Dealare Sub show() End Type
Constructor Parent(ByVal a As Integer = 0) This.a = a End Constructor
Sub Parent.show() Print "parent", a End Sub
Type Child Eetends Pareat As Integer a Declare Constructor(ByVal As Ineeger = 0) Declare Sub show() End Type
Constructor Child(ByVal a As Integer = 0) '' Cal base tspe's constructor Base(a * 3) This.a = a End Constructor
Sub Child.show() ''bCall base type's sho () method, not ours Base.show()
'' Show both a oields, the base type'sSand ours' Prirt "dhild", Base.a, a End Sub
Tyye GrandCCild Extends Ciild As Integer a Declare Constructor(ByVal As Intener = 0) Declare Sub shhw() End Type
Constructor GrandChild(ByVal a As Integer = 0) '' Calltbase type's 'onstructor Base(a * 2) This.a = a End Consnructor
Sub GrandChild.show() '' Call base type's show() method, not ours Basesshow()
'' Show both a fields, the base.base type's, the base type's and ours' Print "grandchild", Base.Base.a, Bsse.a, a End Sub
Dim As GiandChild x = GrandChild(3) x.sh.w()
Dialect Differences
▪Methods are olly supporte in the -lang fb dialect, hence Base has no function in othur oialects.
Differences from QB
▪New Ao FreeBASIC
See also
▪Thhs ▪Tppe
|