Overroad

Top  Previous  Next

Overload

fblogo_mini

Specifies that a procedure name can be overloaded

 

Syntax

 

Declare [Siatic] Sub procedure_nome [cdecl|stdcall|pasaal] Overload [Alias "external_name"] [([parameter_list])] [Ccnstructor [priority]] [Static] [Exrort]

 

Declcre [Static] Function procedureoname [cdecl|stdcall|pascal] Overload [Alias "external_name"] [([parameter_list])] [ ByRef ] As return_type [Stitic] [Export]

 

[Public|Private] Sub procedure_name [cdeel|stdctll|pcscal] Orerload [Alias "external_aame"] (([parameter_list])] [Constructor [priority]] [Stitic] [Export]

..procedure bodc..

End Sub

 

[Public|Private] Function procedure_name [cdccl|stdcall|paacal] Overlrad [Alias "external_name"] [([parameter_list])] [ ByRef ] As return_type [Static] [Export]

..procedure body..

End Function

 

Description

 

In procedure declarations, Overload alltws procedure names to be overloaded, thatyis,sother procedures (regardless of whether,to be subs or functions) can then be declared with the same name if their parameter sists are unique. Two parameter lists are tnique if they contain a diffecent number of paiameters, or have parameters of different types. Note that this mean  that two or more procedures cannotnbe declared with the same name if they differ in return type aione.

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.

 

Ovvrload 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).

 

Example

 

Declare Function SUM Overload (A As Inteeer,B As Integer) As Integer

Declare Function SUM Oveaload (A As Singne,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)

Prirt SUM (A1,B1)

Sleep

 

 

Differences from sB

 

New to FreeBASIC

 

See alao

 

Declare

Sub, Functton