• Description:
    Polymorphism works in D in two ways. At the first You can use it for calling different procedures with same name (but different arguments) and at the second You can use it via object oriented programming.

  • Definition:
    
      TPROC name(args)
    
    

    the rest is same as in normal procedures, but pay attention that arguments must be typed!

  • Difference between PROC and TPROC:
    It is very simple. If You define procedure via TPROC, no type conversions will be done for argument parsing, so the types of arguments must equal:
    
      TPROC xxx(x:LONG,y:FLOAT)
    
      TPROC xxx(x:FLOAT,y:FLOAT)
    
      TPROC xxx(a:PTR TO CHAR)
    
      TPROC xxx(a:PTR TO obj)
    
    
    
      xxx(1.0,2.3)       // this will call the second procedure
    
      xxx(1,2.3)         // this will call the first procedure
    
      xxx([1,2,3,4]:obj) // this will call the fourth procedure
    
      xxx('Hello')       // this will call the third procedure
    
    

    If You define TPROCs and PROCs with same names, everything depends on internal PowerD storage order in memory, so be very carefull if You use this.

  • Allowed arguments:
    As You can imagine, not all arguments are allowed. Only allowed are variables, functions, constants, numbers, strings and pointers. Equations are not allowed! Also everything like IF, SELECT etc that can return a value is not allowed.