Jump to content

same function, different arguments?


Recommended Posts

Can you have the same function name, but different required args?

I had

Func function(arg1, arg2)
     .....
EndFunc

and

Func function(arg1, arg2, arg3)
     .....
EndFunc

but it came up with errors. Just curious if this is possible or ever will be?

Link to comment
Share on other sites

To my knowledge you cant overload functions.

What exactly would you need this option for? Maybe there is another 'clean' solution. If not maybe a 'dirty' one :)

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Can you have the same function name, but different required args?

You can make certain parameters optional by giving them a default value:

Func function(arg1, arg2, arg3=0)
     .....
EndFunc

Now function could be called with (1,2) or (1,2,3). If called with just (1,2) then arg3 would contain a value of 0 (the default value set in the header)

You can also use the macro @NumParams to see how many parameters were given to a function when it was called.

Link to comment
Share on other sites

Can you have the same function name, but different required args?

I had

Func function(arg1, arg2)
     .....
EndFunc

and

Func function(arg1, arg2, arg3)
     .....
EndFunc

but it came up with errors. Just curious if this is possible or ever will be?

<{POST_SNAPBACK}>

overloading is not necessary with autoit because of the ability to have optional arguments and default values for arguments
Link to comment
Share on other sites

Can you have the same function name, but different required args?

but it came up with errors. Just curious if this is possible or ever will be?

You can have optional paramters in your functions, like this:

func myfunc($a, $b, $c=-1)
endfunc

Then you can call it like this:

myfunc(1,2)
myfunc(1,2,3)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...