OVERLOADED functions and subroutines

OVERLOADED functions and subroutines are a useful way of extending your functions and subroutines even further. They are designed to take advantage of the overloaded procedures of the C++ language.

Like OPTIONAL arguments, OVERLOADED functions and subroutines are most easily understood by looking at a working example.


 GLOBAL a$
 GLOBAL b
 GLOBAL c AS DOUBLE

 a$ = One$("hello"," there") : PRINT a$
 b = One(123) : PRINT b
 c# = One(7.01) : PRINT c#

 OVERLOADED FUNCTION One(b) AS INTEGER
  FUNCTION = b
 END FUNCTION

 OVERLOADED FUNCTION One$(a$, b$)
  FUNCTION = MCASE$(JOIN$(2, a$, b$))
 END FUNCTION

 OVERLOADED FUNCTION One#(b#)
  FUNCTION = b# * b#
 END FUNCTION

Result


 Hello There
 123
 49.1401

As you can see, we have created a program that has not one, but three, functions that all share the same name. Also notice that each function also has its own distinct parameter list. This is a compile time feature. That means the compiler must be able to determine which function to use based on its type and parameters. This implies that each FUNCTION or SUB must be unique and distinguishable from one another otherwise the compiler will not be able to figure out which function to use and the compile will be unsuccessful.

Remarks:

OVERLOADED procedures are not compilable with the Pelle's C compiler.

OVERLOADED FUNCTION or SUB procedures are not allowed in a User Defined TYPE structure.

OVERLOADED functions can not use OPTIONAL arguments.