Announcement

Collapse
No announcement yet.

I have another idea!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I have another idea!

    Hello Everyone!


    How would you all feel about function over-loading? This would come in very handy I'm sure.


    Code:
    function AddRecord(lValue as long) as long
    end function
    
    function AddRecord(szName as asciiz) as long
    end function
    Same function name, two diffrent "methods".



    ------------------
    Cheers

  • #2
    Mark,

    Looks like it could be useful in some instances but I wonder how
    the function is supposed to know what the data type is to work
    with ?

    This can be done using a union nested in a structure with the union
    having as many different data types as you like and you write the
    function parameter data type as the structure name.

    FUNCTION MyFunction(MyParameter as MyDataType) as LONG

    About the only problem I can see is that you probably need another
    parameter to tell the function what type of data it is.

    Regards,

    [email protected]

    ------------------
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

    Comment


    • #3
      In C++, the compiler determines which function to call at compile time by examining the parameter types. In PB, I guess it would have to be the same.
      Of course, you can do this now by passing a generic pointer (byte pointer, or ByVal Long, etc), but it puts 100% of the responsibility for passing bad data types on the programmer.
      --Don

      ------------------
      www.basicguru.com/dickinson
      Don Dickinson
      www.greatwebdivide.com

      Comment

      Working...
      X