|
-
Apr 18th, 2003, 08:07 AM
#1
Thread Starter
PowerPoster
Overloaded
What exactly is an overloaded method?
Thanks!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 18th, 2003, 08:27 AM
#2
Fanatic Member
As stated in the Help,
Overloading a procedure means defining it in multiple versions, using the same name but different argument lists. The purpose of overloading is to define several closely related versions of a procedure without having to differentiate them by name. You do this by varying the argument list.
-
Apr 18th, 2003, 08:34 AM
#3
In other words
Code:
Public Sub Hello()
End Sub
Public Sub Hello(a As String)
End Sub
Public Sub Hello(a As Integer)
End Sub
-
Apr 18th, 2003, 09:57 AM
#4
Thread Starter
PowerPoster
umm well how the heck do you know which one you will be using? And couldnt the code be different in each one? That seems totaly confusing and wrong.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 18th, 2003, 10:04 AM
#5
Its the compiler that knows the difference. Yes you can have different code for each. It is the parameter's tht distinguish the difference.
If you pass nothing to sub Hello, then it will run the routine with no parameter. If you pass a string to it Hell("blah") it will run the one with a string parameter.
-
Apr 18th, 2003, 10:05 AM
#6
You know which one will be used because you know what type of parameters are passed. This is meant to provide different variants of the same method, usually the methods do about the samething but add a little extra to handle different types of parameters.
-
Apr 18th, 2003, 10:28 AM
#7
Thread Starter
PowerPoster
OK i see, the intellisense pops up a scrollbar that lets you choose which one to use, letting you know there are multiple methods with the same name.
But still, having multiple methods with the same name seems pretty dumb IMO.
If i had 3 methods which accpeted different parameters and had slightly diferent code it would make much more sense to describe those methods.
VB Code:
'instead of
Sub Test(ByVal TheString As String)
End Sub
Sub Test(ByVal TheInteger As Integer)
End Sub
Sub Test()
End Sub
'it would make more sense to use
Sub TestStr(ByVal TheString As String)
End Sub
Sub TestInt(ByVal TheInteger As Integer)
End Sub
Sub Test()
End Sub
That way you would know exactly what sub you were calling and exactly what it was supposed to do. But anyway... thanks for the info!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 18th, 2003, 01:25 PM
#8
Fanatic Member
Why name the methods 3 different names when they are for the same thing, just different implementations?
Just like the New constructor for an ArrayList - you can create an array list many different ways - but they are all new constructors.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|