strange inheritance proble

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boni

    #1

    strange inheritance proble

    Dear all,
    class A
    overridable sub s1(byval a as integer)
    end sub
    overridable sub s2(byval a as integer, byval b as integer)
    end sub
    end class

    class B
    inherits class A
    overrides sub s1(byval a as integer)
    end sub
    end class

    s1 in both classes is public and has the same signature, but VB complains s1
    in B can't be declared as overrides ... blabla use overload?
    What is wrong here?
    Thanks,
    Boni


  • Cor Ligthert [MVP]

    #2
    Re: strange inheritance proble

    Boni,

    Did you try it already with this[color=blue]
    > inherits class A[/color]
    inherits A

    I hope this helps,

    Cor


    Comment

    • Nick Malik [Microsoft]

      #3
      Re: strange inheritance proble

      Post the actual code, not your shortened, off the top of your head, version
      of it. And post the actual error message, not "blabla"

      Maybe then, some of us can be of more assistance.

      --
      --- Nick Malik [Microsoft]
      MCSD, CFPS, Certified Scrummaster
      http://blogs.msdn.com/nickmalik

      Disclaimer: Opinions expressed in this forum are my own, and not
      representative of my employer.
      I do not answer questions on behalf of my employer. I'm just a
      programmer helping programmers.
      --
      "Boni" <oilia@nospam > wrote in message
      news:uYOlmiUlFH A.3380@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Dear all,
      > class A
      > overridable sub s1(byval a as integer)
      > end sub
      > overridable sub s2(byval a as integer, byval b as integer)
      > end sub
      > end class
      >
      > class B
      > inherits class A
      > overrides sub s1(byval a as integer)
      > end sub
      > end class
      >
      > s1 in both classes is public and has the same signature, but VB complains
      > s1 in B can't be declared as overrides ... blabla use overload?
      > What is wrong here?
      > Thanks,
      > Boni
      >[/color]


      Comment

      • Boni

        #4
        Re: strange inheritance problem

        Actual code:
        Module Module1

        Class A

        Overridable Sub s1(ByVal a As Integer)

        End Sub

        Overridable Sub s1(ByVal a As Integer, ByVal b As Integer)

        End Sub

        End Class

        Class B

        Inherits A

        Overrides Sub s1(ByVal a As Integer)

        End Sub

        End Class

        Sub Main()

        End Sub

        End Module

        (11) : warning BC40003: sub 's1' shadows an overloadable member declared in
        the base class 'A'. If you want to overload the base method, this method
        must be declared 'Overloads'.

        WARNING: sub 's1' shadows an overloadable member declared in the base class
        'A'. If you want to overload the base method, this method must be declared
        'Overloads'.



        Why b::s1 can't override A::S1


        Comment

        • Dragon

          #5
          Re: strange inheritance problem

          Hi,
          [color=blue]
          > Why b::s1 can't override A::S1[/color]

          It can, why not? 8=]

          But since you have two s1's in base class, you need to mark s1 from derived
          class with Overloads to show you are still overloading, as compiler
          suggests.

          HTH

          Roman


          Comment

          • Boni

            #6
            Re: strange inheritance problem

            But between overrides and overloads there is a big difference. Look in main
            of following example. A::s1 is called where I want B::s1 to be called (just
            as an example 2).
            Please could somebody to help me to find a solution for that strange
            problem.
            Example 1:
            Module Module1
            Class A

            Overridable Sub s1(ByVal a As Integer)

            Console.WriteLi ne("A")

            End Sub

            Overridable Sub s1(ByVal a As Integer, ByVal b As Integer)

            End Sub

            End Class

            Class B

            Inherits A

            Overloads Sub s1(ByVal a As Integer)

            Console.WriteLi ne("B")

            End Sub

            End Class

            Sub Main()

            Dim oB As New B

            Dim pA As A = oB

            pA.s1(110)

            End Sub

            End Module





            Example2:

            Module Module1

            Class A

            Overridable Sub s1(ByVal a As Integer)

            Console.WriteLi ne("A")

            End Sub

            End Class

            Class B

            Inherits A

            Overrides Sub s1(ByVal a As Integer)

            Console.WriteLi ne("B")

            End Sub

            End Class

            Sub Main()

            Dim oB As New B

            Dim pA As A = oB

            pA.s1(110)

            End Sub

            End Module


            Comment

            • Dragon

              #7
              Re: strange inheritance problem

              Ehh, it seems that you misunderstood me.

              You shouldn't replace Overrides by Overloads, but just add Overloads
              modifier, e.g.:

              ~
              Overloads Overrides Sub s1(ByVal a As Integer)

              Console.WriteLi ne("B")

              End Sub

              ~

              Try to change example 1 this way and it will work fine.


              Comment

              • Boni

                #8
                Re: strange inheritance problem

                Thanks!!! You are right. But I must say it makes no sence for me :) . I
                don't understand why it is done like this.
                Why only overrides was not enougth for VB inventors?
                "Dragon" <no@spam.please > schrieb im Newsbeitrag
                news:umuOCVglFH A.1480@TK2MSFTN GP10.phx.gbl...[color=blue]
                > Ehh, it seems that you misunderstood me.
                >
                > You shouldn't replace Overrides by Overloads, but just add Overloads
                > modifier, e.g.:
                >
                > ~
                > Overloads Overrides Sub s1(ByVal a As Integer)
                >
                > Console.WriteLi ne("B")
                >
                > End Sub
                >
                > ~
                >
                > Try to change example 1 this way and it will work fine.
                >
                >[/color]


                Comment

                • Dragon

                  #9
                  Re: strange inheritance problem

                  > I don't understand why it is done like this.

                  Nor do I. 8=0]

                  Probably, the logic was: if you override an Overloads member then your
                  method must be declared Overloads too.
                  [color=blue]
                  > Why only overrides was not enougth for VB inventors?[/color]

                  You better should ask VB inventors. ;—)


                  Comment

                  Working...