Results 1 to 12 of 12

Thread: is it possible to overload without canceling the the content of the overloaded method

  1. #1

    Thread Starter
    Hyperactive Member fabianus's Avatar
    Join Date
    Sep 2004
    Location
    Paris
    Posts
    402

    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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: is it possible to overload without canceling the the content of the overloaded method

    You could try MyBase.MethodName

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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:
    1. Public sub MySpecialSub()
    2. [B]Mybase.MySpecialSub()[/B]
    3. '...
    4. 'the new code goes here and occurs after the base class has run its own version
    5. '...
    6. end sub

    I don't live here any more.

  4. #4

    Thread Starter
    Hyperactive Member fabianus's Avatar
    Join Date
    Sep 2004
    Location
    Paris
    Posts
    402

    Smile 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

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  6. #6
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    Re: is it possible to overload without canceling the the content of the overloaded method

    Really? - so you couldn't have:
    VB Code:
    1. Public Shadows Function TestFunction ()
    2.    ' ...
    3.    'Do some stuff in here
    4.    ' ...
    5.    MyBase.TestFunction
    6. End function
    I never knew that.

  7. #7

    Thread Starter
    Hyperactive Member fabianus's Avatar
    Join Date
    Sep 2004
    Location
    Paris
    Posts
    402

    Question 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?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.

  9. #9
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: is it possible to overload without canceling the the content of the overloaded me

    Quote 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:
    1. Public Function rtn() As String
    2.         Return "test string"
    3.     End Function
    4.  
    5.     Public Function rtn(ByVal s As String) As String
    6.         Return "test string " & s
    7.     End Function
    8.  
    9.     Public Function rtn() As Integer
    10.         Return 12
    11.     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.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: is it possible to overload without canceling the the content of the overloaded me

    Quote Originally Posted by Briantcva
    Correct except for differing return type. Overloaded methods can only differ in arguments, not in return type.
    VB Code:
    1. Public Function rtn() As String
    2.         Return "test string"
    3.     End Function
    4.  
    5.     Public Function rtn(ByVal s As String) As String
    6.         Return "test string " & s
    7.     End Function
    8.  
    9.     Public Function rtn() As Integer
    10.         Return 12
    11.     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.

  11. #11
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    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.

  12. #12
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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
  •  



Click Here to Expand Forum to Full Width