Repository navigation
Overload
Home › Procedures › Overload
Specifies that a procedure name can be overloaded
Declare [Static] Sub procedure_name [cdecl|stdcall|pascal] Overload [Alias "external_name"] [([parameter_list])] [Constructor [priority]] [Static] [Export]
Declare [Static] Function procedure_name [cdecl|stdcall|pascal] Overload [Alias "external_name"] [([parameter_list])] [ ByRef ] As return_type [Static] [Export]
[Public|Private] Sub procedure_name [cdecl|stdcall|pascal] Overload [Alias "external_name"] [([parameter_list])] [Constructor [priority]] [Static] [Export]
..procedure body..
End Sub
[Public|Private] Function procedure_name [cdecl|stdcall|pascal] Overload [Alias "external_name"] [([parameter_list])] [ ByRef ] As return_type [Static] [Export]
..procedure body..
End FunctionIn procedure declarations, Overload allows procedure names to be overloaded, that is, other procedures (regardless of whether to be subs or functions) can then be declared with the same name if their parameter lists are unique. Two parameter lists are unique if they contain a different number of parameters, or have parameters of different types. Note that this means that two or more procedures cannot be declared with the same name if they differ in return type alone.
A variadic procedure name can never be overloaded.
Once a procedure name has been declared overloaded, further declarations using the name need not specify Overload, but it is allowed.
Overload is not necessary in member procedure declarations, as they are always implicitly overloaded.
When calling an overloaded procedure name, a match score is calculated comparing the call argument types with the parameter types for each candidate procedure (major resolution on datatypes themselves, minor resolution on datatype sizes).
The highest matching score wins. If this highest score is too low, or if several overloaded procedures have the same highest score, the compiler then generates an error at compile time (no matching procedure, or ambiguous call).
- New to FreeBASIC
Declare Function SUM Overload (A As Integer,B As Integer) As Integer
Declare Function SUM Overload (A As Single,B As Single) As Single
Function SUM (A As Integer,B As Integer) As Integer
Function=A+B
End Function
Function SUM (A As Single,B As Single) As Single
Function=A+B
End Function
Dim As Integer A,B
Dim As Single A1,B1
A=2
B=3
A1=2.
b1=3.
Print SUM(A,B)
Print SUM (A1,B1)
SleepCategory: Procedures
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.
- 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)
- 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