|
-
Jun 16th, 2005, 09:18 AM
#1
Thread Starter
Hyperactive Member
is it possible to overload without canceling the the content of the overloaded method
is it possible to overload without canceling the the content of the overloaded method?
So that you may complete a methode without kicking off everything what is in the inherited method?
Thank you for any advice!
Fabian
-
Jun 16th, 2005, 09:42 AM
#2
Re: is it possible to overload without canceling the the content of the overloaded method
You could try MyBase.MethodName
-
Jun 16th, 2005, 09:49 AM
#3
Re: is it possible to overload without canceling the the content of the overloaded method
To elaborate on my distinguished friend's brief but accurate impartation, you should call the inherited method from within the inheriting method.
VB Code:
Public sub MySpecialSub()
[B]Mybase.MySpecialSub()[/B]
'...
'the new code goes here and occurs after the base class has run its own version
'...
end sub
I don't live here any more.
-
Jun 16th, 2005, 09:57 AM
#4
Thread Starter
Hyperactive Member
Re: is it possible to overload without canceling the the content of the overloaded me
Hi wossname and mendhak,
it is true that the "more elaborated" version helps me to understand :-)
In fact it is about the page_load () sub in asp.net. I thought that I could do as you tell, but I wanted to avoid to have to call in each page-class inhereting form my customPage class (that inherits form zumiControls.zumiPage... which inherits from System.Web.UI.Page :-)))
the page_load sub from mybase.
Seems as I won't come around this :-(
Thank you very much - both of you...
Fabian
-
Jun 16th, 2005, 10:02 AM
#5
Re: is it possible to overload without canceling the the content of the overloaded method
Its not uncommon to use MyBase.Blah() in this way. Its perfectly acceptable to do so. And as such the compiler enforces that it must be the first statement in such an overloaded sub.
-
Jun 16th, 2005, 10:06 AM
#6
Hyperactive Member
Re: is it possible to overload without canceling the the content of the overloaded method
Really? - so you couldn't have:
VB Code:
Public Shadows Function TestFunction ()
' ...
'Do some stuff in here
' ...
MyBase.TestFunction
End function
I never knew that.
-
Jun 16th, 2005, 10:10 AM
#7
Thread Starter
Hyperactive Member
Re: is it possible to overload without canceling the the content of the overloaded me
By the way
"I invented the Internet." - Shaggy Hiker
Who is Shaggy Hiker?
-
Jun 16th, 2005, 07:57 PM
#8
Re: is it possible to overload without canceling the the content of the overloaded method
Can I just point out that it sounds like we are talking about OVERRIDING, not OVERLOADING. Overloading means same name, different arguments and possibly different return type.
-
Jun 16th, 2005, 09:23 PM
#9
Fanatic Member
Re: is it possible to overload without canceling the the content of the overloaded me
 Originally Posted by jmcilhinney
Can I just point out that it sounds like we are talking about OVERRIDING, not OVERLOADING. Overloading means same name, different arguments and possibly different return type.
Correct except for differing return type. Overloaded methods can only differ in arguments, not in return type.
VB Code:
Public Function rtn() As String
Return "test string"
End Function
Public Function rtn(ByVal s As String) As String
Return "test string " & s
End Function
Public Function rtn() As Integer
Return 12
End Function
will generate the following error: ''Public Function rtn() As String' and 'Public Function rtn() As Integer' cannot overload each other because they differ only by return types.
-
Jun 16th, 2005, 09:37 PM
#10
Re: is it possible to overload without canceling the the content of the overloaded me
 Originally Posted by Briantcva
Correct except for differing return type. Overloaded methods can only differ in arguments, not in return type.
VB Code:
Public Function rtn() As String
Return "test string"
End Function
Public Function rtn(ByVal s As String) As String
Return "test string " & s
End Function
Public Function rtn() As Integer
Return 12
End Function
will generate the following error: ''Public Function rtn() As String' and 'Public Function rtn() As Integer' cannot overload each other because they differ only by return types.
I think you'll find that I was completely correct. Overloaded functions CAN have differing return types if you want but they MUST have differing argument lists, which is what I said previously: same name, different arguments and possibly different return types.
Edit:
Briantcva, you'll notice that the compiler complained about your first and third overloads because they do differ by only return type. It would not, however, have complained about the second and third, which differ by argument list and return type.
Last edited by jmcilhinney; Jun 16th, 2005 at 09:57 PM.
-
Jun 17th, 2005, 08:12 AM
#11
Fanatic Member
Re: is it possible to overload without canceling the the content of the overloaded method
Interesting. I really had no idea (obviously). I seem to remember [early on in working w/ .Net] trying to just vary return type, getting that error and assuming that you couldn't vary return type. Thanks for the tip.
-
Jun 17th, 2005, 08:16 AM
#12
Re: is it possible to overload without canceling the the content of the overloaded method
Overloading does not preclude implicit overriding.
The previous concepts stand.
Shaggy Hiker is a fellow VBF member. However that quote may be recycled from the famous Al Gore utterance.
I don't live here any more.
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
|