strange inheritance proble

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

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
 
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.
 
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
 
Hi,
Why b::s1 can't override A::S1

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
 
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.WriteLine("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.WriteLine("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.WriteLine("A")

End Sub

End Class

Class B

Inherits A

Overrides Sub s1(ByVal a As Integer)

Console.WriteLine("B")

End Sub

End Class

Sub Main()

Dim oB As New B

Dim pA As A = oB

pA.s1(110)

End Sub

End Module
 
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.WriteLine("B")

End Sub

~

Try to change example 1 this way and it will work fine.
 
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?
 
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.
Why only overrides was not enougth for VB inventors?

You better should ask VB inventors. ;—)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top