Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v3:subroutines [2024/07/30 22:33] – [Overloading] neilsv3:subroutines [2024/07/30 22:43] (current) – [Overloading] neils
Line 111: Line 111:
 Subroutine overloading, commonly known as method overloading in object-oriented programming languages, refers to the ability to create multiple subroutines with the same name but different parameters. This feature allows a programmer to define different ways to call a subroutine based on the types and number of arguments passed. Subroutine overloading, commonly known as method overloading in object-oriented programming languages, refers to the ability to create multiple subroutines with the same name but different parameters. This feature allows a programmer to define different ways to call a subroutine based on the types and number of arguments passed.
  
-Overloaded subroutines have the same name but differ in the type, number, or both type and number of parameters. The appropriate subroutine to call is determined at compile-time based on the arguments provided in the call.+Overloaded subroutines have the same name but differ in the type, number, or both type and number of parameters. 
 + 
 +==== Compile-Time Polymorphism ==== 
 + 
 +The appropriate subroutine to call is determined at compile-time based on the arguments provided in the call.
  
 Consider the following example: Consider the following example:
  
-  SUB test (AS INTSTATIC +  SUB PrintMessage(msg AS STRING * 16
-    PRINT "a is an integer: "; a+      PRINT msg
   END SUB   END SUB
      
-  SUB test (AS STRING * 16) OVERLOAD STATIC +  SUB PrintMessage(msg AS STRING * 16, num AS INT) OVERLOAD 
-    PRINT "a is a string: "; a+      PRINT msg; " "; num
   END SUB   END SUB
      
-  CALL test(5+  CALL PrintMessage("Hello, XC=BASIC!"
-  CALL test("hello")+  CALL PrintMessage("The number is", 42)
  
 <adm warning> <adm warning>