By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,641 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,641 IT Pros & Developers. It's quick & easy.

strange inheritance proble

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies

P: n/a
Boni,

Did you try it already with this
inherits class A

inherits A

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
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:uY**************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a
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
Nov 21 '05 #5

P: n/a
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
Nov 21 '05 #6

P: n/a
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.
Nov 21 '05 #7

P: n/a
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:um**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 21 '05 #8

P: n/a
> 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. ;)
Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.