Author Topic: overload function  (Read 2016 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
overload function
« on: August 15, 2011, 02:48:38 AM »
Deleted
« Last Edit: May 07, 2015, 11:26:07 AM by Peter »

Charles Pegge

  • Guest
Re: overload function
« Reply #1 on: August 15, 2011, 04:16:10 AM »
Hi Peter,

I don't have your window.h but I checked the functions and they were basically okay with the Oxygen I am working on. I am posting the latest DLL, in case it does not work with your version.


Code: OxygenBasic
  1.  
  2. ' include "window.h"
  3.  
  4. 'def lila  0xFFC8C8
  5. 'def green 0x00FF00
  6.  
  7. 'SetWindow "Overload Function",640,480,ws_overlapped
  8. 'SetFont 12,24,0,0
  9.  
  10. Declare Function Output(sys x, y) as long
  11. Declare Function Output(single d) as single
  12. Declare Function Output(string c) as string
  13.  
  14. 'While WinExit=0
  15. sys a, string s, single f
  16. 'cls
  17. a= Output(2, 4)         ' is Okay here
  18. print typeof a
  19. print a
  20. 'SetText a,32,32,Lila    
  21.  
  22. f= Output(45.0)         ' here flops OxygenBasic
  23. print typeof f
  24. print f
  25. 'SetText f,32,64,Lila
  26.  
  27. s= Output("HELLO")      ' here fails OxygenBasic
  28. print typeof s
  29. print s
  30. 'SetText s,32,96,Green
  31.  
  32. 'DoEvents
  33. 'Wend
  34. 'WinEnd
  35.  
  36. Function Output(sys x, y) as long
  37. Return y*x
  38. End Function
  39.  
  40. Function Output(single d) as single
  41. Return d*pi()/180 '<----removed outer brackets
  42. End Function
  43.  
  44. Function Output(string c) as string
  45. Return c + " Okay"
  46. End Function

Here is a compact demo of overloaded functions :)

Code: OxygenBasic
  1.  
  2. 'overloaded functions in Oxygen
  3.  
  4. function f(double d) {print "Double " d}
  5. function f(long d) {print "Long " d}
  6. function f(string d) {print "String " d}
  7.  
  8.  
  9. f 42.5
  10. f 4
  11. f "Hello"
  12.  
Charles
« Last Edit: August 15, 2011, 04:51:44 AM by Charles Pegge »