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
Printable View
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
You could try MyBase.MethodName
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
:wave:
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
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.
Really? - so you couldn't have:
I never knew that. :ehh:VB Code:
Public Shadows Function TestFunction () ' ... 'Do some stuff in here ' ... MyBase.TestFunction End function
By the way
"I invented the Internet." - Shaggy Hiker
Who is Shaggy Hiker?
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.Quote:
Originally Posted by jmcilhinney
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.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
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.Quote:
Originally Posted by Briantcva
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.
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.
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.