Sign in to follow this  
Followers 0
Arrrghmatey

same function, different arguments?

5 posts in this topic

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?

Share this post


Link to post
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)

Share this post


Link to post
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.

Share this post


Link to post
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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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 *

Share this post


Link to post
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
Sign in to follow this  
Followers 0