Repository navigation
Base Member Access
Home › User Defined Types › Base (Member Access)
Provides explicit access to base type members in non-static methods of a Type
Base.member
Base [ .Base ... ] .memberBase 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 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 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() always calls the base method and never the overriding method.
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).
- Methods are only supported in the -lang fb dialect, hence
Basehas no function in other dialects.
- New to FreeBASIC
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)
'' Call base type's constructor
Base(a * 3)
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
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)
'' Call base type's constructor
Base(a * 2)
This.a = a
End Constructor
Sub GrandChild.show()
'' Call base type's show() method, not ours
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)
x.show()Category: User Defined Types
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing