Author Topic: optional and overload  (Read 57 times)

0 Members and 1 Guest are viewing this topic.

jcfuller

  • Jr. Member
  • **
  • Posts: 85
optional and overload
« on: February 13, 2018, 04:03:33 AM »
Charles,
Will optional parameters for overloaded functions be offered in the future or are they supposed to work now?
Your overloaded example works fine but adding optional causes only the last foo function to be called.

Code: [Select]

% filename "overloading2.exe"
uses rtl64

'FUNCTION OVERLOADING
'====================

function foo (long v, optional string os) as string
print os
return "long " v
end function

function foo (double v, optional string os ) as string
print os
return "double " v
end function

function foo (string v, optional string os) as string
print os
return "string " v
end function


long l=42
double d=42.5
string s="43"

print foo (l,"l")
print foo (d,"d")
print foo (s,"s")


Another related question
Is the keyword "optional" optional :) with functions that have default parameters?
I noticed in some of your examples you just assign a value:
Function abc(sys i,sys n=17) As sys
Function abc(sys i,optional sys n=17) As sys

James

Charles Pegge

  • Author
  • *****
  • Posts: 3365
    • Oxygen Basic
Re: optional and overload
« Reply #1 on: February 14, 2018, 06:30:26 AM »
Hi James,

This release fixes the function overloading  /  optional param  problem.

Parameter default values, however, are not compatible with function overloading, but you can combine them with optional where the functions are not overloaded.

https://github.com/Charles-Pegge/OxygenBasic/blob/master/OxygenProgress.zip



PS:

I've added hibyte and lobyte as core keywords
« Last Edit: February 14, 2018, 09:23:54 AM by Charles Pegge »