Oxygen Basic

Information => Development => Topic started by: jcfuller on January 15, 2018, 06:17:47 AM

Title: overloaded functions
Post by: jcfuller on January 15, 2018, 06:17:47 AM
Charles,
  Does OxygenBasic have overloaded functions similar to FreeBasic?
I only found one reference in the MathComplex.inc file, but no examples of use with simple functions that have the same name but different parameters.

James
Title: Re: overloaded functions
Post by: jcfuller on January 15, 2018, 07:12:52 AM
It looks like this was a duh question as I just created different functions with the same name but different parameters and it compiled and ran fine without any "OVERLOAD" keyword!!
Fine work Charles.

James
Title: Re: overloaded functions
Post by: Charles Pegge on January 16, 2018, 08:51:23 AM
As an alternative to function overloading, there is also default parameters, which can save function duplication:

Code: [Select]
function f(int a=1, b=2, string c="ok") as int
...
end function

You can call such a function in the usual way, but you may also specify parameter assignments individually:

Code: [Select]
f( b=42, c="X" )


Title: Re: overloaded functions
Post by: jack on January 16, 2018, 02:45:21 PM
@Charles Pegge
I thought that you mentioned at one time that you would take-out function overloading, it seems function overloading is still supported, can you also overload math operators?
Title: Re: overloaded functions
Post by: Charles Pegge on January 17, 2018, 03:59:26 AM
Hello jack,

Selecting the right function, and converting parameters to match the type where necessary, is extra work for the compiler. However, occasionally there are no easy alternatives, like getter and setter functions.

I'm keeping very quiet about operator overloading. I am still working on it to get the best performance for both high level and assembler level operations. A type can have its own set of operations, based on macros, so the overhead of calling operator functions is avoided.
Title: Re: overloaded functions
Post by: jack on January 17, 2018, 05:56:20 AM
thank you :)