Revision history for KeyPgBase
Revision [23776]
Last edited on 2019-12-16 10:07:00 by fxm [Added note on accessing operator members of a base type]Additions:
**Note:** There is no specific syntax with ##**Base**## 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).
Revision [22727]
Edited on 2019-06-26 11:32:24 by fxm [added 'Extends Zstring' and 'Extends Wstring' links]Additions:
- ##[[KeyPgExtendsZstring|Extends Zstring]]##
- ##[[KeyPgExtendsWstring|Extends Wstring]]##
- ##[[KeyPgExtendsWstring|Extends Wstring]]##
Additions:
- ##[[KeyPgOptionbase|Option Base]]##
Deletions:
Additions:
Provides explicit access to base type members in non-static methods of a ##[[KeyPgType|Type]]##
##**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 ##[[KeyPgExtends|Extends]]##.
- Methods are only supported in the //[[CompilerOptlang|-lang fb]]// dialect, hence ##**Base**## has no function in other dialects.
- ##[[KeyPgBaseInit|Base (initializer)]]##
- ##[[KeyPgThis|This]]##
- ##[[KeyPgType|Type]]##
- ##[[KeyPgExtends|Extends]]##
- ##[[KeyPgOptionBase|Option Base]]##
##**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 ##[[KeyPgExtends|Extends]]##.
- Methods are only supported in the //[[CompilerOptlang|-lang fb]]// dialect, hence ##**Base**## has no function in other dialects.
- ##[[KeyPgBaseInit|Base (initializer)]]##
- ##[[KeyPgThis|This]]##
- ##[[KeyPgType|Type]]##
- ##[[KeyPgExtends|Extends]]##
- ##[[KeyPgOptionBase|Option Base]]##
Deletions:
##**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 ##[[KeyPgExtends Extends]]##.
- Methods are only supported in the //[[CompilerOptlang -lang fb]]// dialect, hence ##**Base**## has no function in other dialects.
- ##[[KeyPgBaseInit Base (initializer)]]##
- ##[[KeyPgThis This]]##
- ##[[KeyPgType Type]]##
- ##[[KeyPgExtends Extends]]##
- ##[[KeyPgOptionBase Option Base]]##
Revision [17255]
Edited on 2014-09-09 15:40:56 by FxMwikki [For virtual methods, base.method() always calls the base method and never the overriding method.]Additions:
For virtual methods, base.method() always calls the base method and never the overriding method.
Revision [16514]
Edited on 2012-12-26 13:18:33 by FxMwikki [Rename 'overriding' when misleading by using 'shadowing']Additions:
##**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.
Deletions:
Revision [16498]
Edited on 2012-12-22 08:08:48 by FxMwikki [Precise wording: added 'non-static' before 'method']Additions:
Provides explicit access to base type members in non-static methods of a ##[[KeyPgType Type]]##
##**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 ##[[KeyPgExtends Extends]]##.
##**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 ##[[KeyPgExtends Extends]]##.
Deletions:
##**Base**## provides a way to explicitly access members of a specific base type, in the context of methods of a user-defined type derived from another type using ##[[KeyPgExtends Extends]]##.
Revision [16184]
Edited on 2012-05-23 18:21:45 by DkLwikki [Base() initializer description moved to new page]Additions:
##**Base**## provides a way to explicitly access members of a specific base type, in the context of methods of a user-defined type derived from another type using ##[[KeyPgExtends Extends]]##.
By using ##**Base**## repeatedly, as in ##base.base.base.member##, it is possible to access any desired base type, in case there are multiple levels of inheritance.
##**Base**## is especially useful when local variables or members of a derived type override a base type's members by using the same identifiers. ##**Base**## then allows unambiguous access to the base type.
By using ##**Base**## repeatedly, as in ##base.base.base.member##, it is possible to access any desired base type, in case there are multiple levels of inheritance.
##**Base**## is especially useful when local variables or members of a derived type override a base type's members by using the same identifiers. ##**Base**## then allows unambiguous access to the base type.
Deletions:
Revision [16183]
Edited on 2012-05-23 18:20:08 by DkLwikki [Base() initializer description moved to new page]Additions:
{{fbdoc item="title" value="BASE (member access)"}}----
- ##[[KeyPgBaseInit Base (initializer)]]##
- ##[[KeyPgBaseInit Base (initializer)]]##
Deletions:
//or//
**base**()
##**Base()**## can also be used to call the base type constructor (at creation step) from within a directly derived type's constructor (where it must be the first statement), in order to ensure the base type is properly constructed. By using once ##**Base()**## in first statement of each derived type's constructor, it is possible to call any desired base type constructor, in case there are multiple levels of inheritance.
##**Base()**## is not a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()## statement which can be used wherever inside any member procedure and which always induces base type reconstruction.
Revision [16128]
Edited on 2012-02-14 06:53:16 by FxMwikki [Add use details about Base() that is not a shortcut for Base.Constructor() + extended example]Additions:
Type Parent
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare 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 extends Parent
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare Sub show()
End Type
Constructor Child(ByVal a As Integer = 0)
Base(a * 3)
This.a = a
End Constructor
Sub Child.show()
Base.show()
Print "child", Base.a, a
End Sub
Type GrandChild extends Child
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare Sub show()
End Type
Constructor GrandChild(ByVal a As Integer = 0)
Base(a * 2)
This.a = a
End Constructor
Sub GrandChild.show()
Base.show()
'' Show both a fields, the base.base type's, the base type's and ours'
Print "grandchild", Base.Base.a, Base.a, a
End Sub
Dim As GrandChild x = GrandChild(3)
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare 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 extends Parent
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare Sub show()
End Type
Constructor Child(ByVal a As Integer = 0)
Base(a * 3)
This.a = a
End Constructor
Sub Child.show()
Base.show()
Print "child", Base.a, a
End Sub
Type GrandChild extends Child
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare Sub show()
End Type
Constructor GrandChild(ByVal a As Integer = 0)
Base(a * 2)
This.a = a
End Constructor
Sub GrandChild.show()
Base.show()
'' Show both a fields, the base.base type's, the base type's and ours'
Print "grandchild", Base.Base.a, Base.a, a
End Sub
Dim As GrandChild x = GrandChild(3)
Deletions:
as integer a
declare constructor(byval as integer)
declare sub show()
end type
constructor Parent(byval a as integer)
this.a = a
end constructor
sub Parent.show()
print "parent", a
end sub
type Child extends Parent
as integer a
declare constructor(byval as integer)
declare sub show()
end type
constructor Child(byval a as integer)
base(a * 2)
this.a = a
end constructor
sub Child.show()
base.show()
print "child", base.a, a
end sub
dim as Child x = Child(3)
Revision [16127]
Edited on 2012-02-14 06:44:03 by FxMwikki [Add use details about Base() that is not a shortcut for Base.Constructor()]Additions:
##**Base()**## can also be used to call the base type constructor (at creation step) from within a directly derived type's constructor (where it must be the first statement), in order to ensure the base type is properly constructed. By using once ##**Base()**## in first statement of each derived type's constructor, it is possible to call any desired base type constructor, in case there are multiple levels of inheritance.
##**Base()**## is not a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()## statement which can be used wherever inside any member procedure and which always induces base type reconstruction.
##**Base()**## is not a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()## statement which can be used wherever inside any member procedure and which always induces base type reconstruction.
Deletions:
Revision [16126]
Edited on 2012-02-14 02:25:36 by FxMwikki [Base() is not a shortcut for Base.Constructor() because it does not induce reconstruction]Additions:
##**Base()**## can also be used to call the base type constructor (at creation step) from within a directly derived type's constructor (where it must be the first statement), in order to ensure the base type is properly constructed. It is not a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()## statement which can be used inside any member procedure and which always induces base type reconstruction.
Deletions:
Revision [16125]
Edited on 2012-02-13 15:07:05 by FxMwikki [Base() is not a shortcut for Base.Constructor() because it does not induce reconstruction]Additions:
##**Base()**## can also be used to call the base type constructor (at creation step) from within a derived type's constructor (it must be the first statement), in order to ensure the base type is properly constructed. It is not a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()## statement which can be used inside any member procedure and which always induces reconstruction of the base type.
Deletions:
Additions:
##**Base**## provides a way to explicitly access members of a specific base type, in the context of methods of a user-defined type derived from another type using ##[[KeyPgExtends Extends]]##. This is especially useful when local variables or members of a derived type override a base type's members if they are using the same identifiers. ##**Base**## then allows unambiguous access to the base type. By using ##**Base**## repeatedly, as in ##base.base.base.member##, it is possible to access any desired base type, in case there are multiple levels of inheritance.
##**Base**## can also be used to call base type constructors from within a derived type's constructors, in order to ensure the base type is properly initialized. Currently this appears to be a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()##.
- Methods are only supported in the //[[CompilerOptlang -lang fb]]// dialect, hence ##**Base**## has no function in other dialects.
##**Base**## can also be used to call base type constructors from within a derived type's constructors, in order to ensure the base type is properly initialized. Currently this appears to be a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()##.
- Methods are only supported in the //[[CompilerOptlang -lang fb]]// dialect, hence ##**Base**## has no function in other dialects.
Deletions:
**Base** can also be used to call base type constructors from within a derived type's constructors, in order to ensure the base type is properly initialized. Currently this appears to be a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()##.
- Methods are only supported in the //[[CompilerOptlang -lang fb]]// dialect, hence **Base** has no function in other dialects.
Additions:
Provides explicit access to base type members in methods of a ##[[KeyPgType Type]]##
**base**.//member//
**base** [ .**base** ... ] .//member//
//or//
**base**()
**Base** provides a way to explicitly access members of a specific base type, in the context of methods of a user-defined type derived from another type using ##[[KeyPgExtends Extends]]##. This is especially useful when local variables or members of a derived type override a base type's members if they are using the same identifiers. **Base** then allows unambiguous access to the base type. By using **Base** repeatedly, as in ##base.base.base.member##, it is possible to access any desired base type, in case there are multiple levels of inheritance.
**Base** can also be used to call base type constructors from within a derived type's constructors, in order to ensure the base type is properly initialized. Currently this appears to be a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()##.
{{fbdoc item="filename" value="examples/manual/udt/base.bas"}}%%(freebasic)
type Parent
as integer a
declare constructor(byval as integer)
declare sub show()
end type
constructor Parent(byval a as integer)
this.a = a
end constructor
sub Parent.show()
print "parent", a
end sub
type Child extends Parent
as integer a
declare constructor(byval as integer)
declare sub show()
end type
constructor Child(byval a as integer)
'' Call base type's constructor
base(a * 2)
this.a = a
end constructor
sub Child.show()
'' Call base type's show() method, not ours
base.show()
'' Show both a fields, the base type's and ours'
print "child", base.a, a
end sub
dim as Child x = Child(3)
x.show()
%%
- Methods are only supported in the //[[CompilerOptlang -lang fb]]// dialect, hence **Base** has no function in other dialects.
- New to ""FreeBASIC""
- ##[[KeyPgThis This]]##
**base**.//member//
**base** [ .**base** ... ] .//member//
//or//
**base**()
**Base** provides a way to explicitly access members of a specific base type, in the context of methods of a user-defined type derived from another type using ##[[KeyPgExtends Extends]]##. This is especially useful when local variables or members of a derived type override a base type's members if they are using the same identifiers. **Base** then allows unambiguous access to the base type. By using **Base** repeatedly, as in ##base.base.base.member##, it is possible to access any desired base type, in case there are multiple levels of inheritance.
**Base** can also be used to call base type constructors from within a derived type's constructors, in order to ensure the base type is properly initialized. Currently this appears to be a shortcut for ##**Base**.[[KeyPgConstructor Constructor]]()##.
{{fbdoc item="filename" value="examples/manual/udt/base.bas"}}%%(freebasic)
type Parent
as integer a
declare constructor(byval as integer)
declare sub show()
end type
constructor Parent(byval a as integer)
this.a = a
end constructor
sub Parent.show()
print "parent", a
end sub
type Child extends Parent
as integer a
declare constructor(byval as integer)
declare sub show()
end type
constructor Child(byval a as integer)
'' Call base type's constructor
base(a * 2)
this.a = a
end constructor
sub Child.show()
'' Call base type's show() method, not ours
base.show()
'' Show both a fields, the base type's and ours'
print "child", base.a, a
end sub
dim as Child x = Child(3)
x.show()
%%
- Methods are only supported in the //[[CompilerOptlang -lang fb]]// dialect, hence **Base** has no function in other dialects.
- New to ""FreeBASIC""
- ##[[KeyPgThis This]]##
Deletions:
- ##[[KeyPgOpIs Operator Is]]##
Additions:
Provides access to the derived type's base type
Deletions:
Additions:
- ##[[KeyPgOpIs Operator Is]]##