Author Topic: overloaded functions  (Read 2252 times)

0 Members and 1 Guest are viewing this topic.

jcfuller

  • Guest
overloaded functions
« 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

jcfuller

  • Guest
Re: overloaded functions
« Reply #1 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

Charles Pegge

  • Guest
Re: overloaded functions
« Reply #2 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" )



jack

  • Guest
Re: overloaded functions
« Reply #3 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?

Charles Pegge

  • Guest
Re: overloaded functions
« Reply #4 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.

jack

  • Guest
Re: overloaded functions
« Reply #5 on: January 17, 2018, 05:56:20 AM »
thank you :)