Sorry - my mistake. I misunderstood the problem. When you add another MySub
with different signature to Class1, you'll have to use the overloads keyword
there. So your two classes should look something like:
Public Class Class1
Public Overridable Overloads Sub MySub()
End Sub
Public Overridable Overloads Sub MySub(ByVal i As Int16)
End Sub
End Class
Public Class Class2
Inherits Class1
Public Overrides Sub MySub()
End Sub
End Class
I think you should be fine then. However, if you are going to override the
MySub with the new signature as well, then I think you don't need the
Overrides keyword anymore. Only the Overloaded is needed. Something like:
Public Class Class1
Public Overridable Overloads Sub MySub()
End Sub
Public Overridable Overloads Sub MySub(ByVal i As Int16)
End Sub
End Class
Public Class Class2
Inherits Class1
Public Overloads Sub MySub()
End Sub
Public Overloads Sub MySub(ByVal i As Int16)
End Sub
End Class
However, I'm not absolutely sure of that but I do remember reading that
somewhere. You can try with the Overrides or without it and see which one
works. But yes - the first piece of code should resolve what you are looking
for.
hope that helps..
Imran.
"Amin Sobati" <am***@morva.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Thanks Imran,
But I think I don't manipulate it's signature. If my overriding is
considered as signature change, then why it is not for the first
situation(when there are one MySub in Class1, instead of two overloaded)?
In the first code the I pasted here, I can override without any problem.
Problem occurs as I add another MySub(with different signature) to Class1.
Amin
"Imran Koradia" <no****@microso ft.com> wrote in message
news:#n******** ******@TK2MSFTN GP15.phx.gbl... Overriding is basically changing the way the method/property behaves;
you cannot change the signature of a method/property when overriding. Take a
look at this document for rules on overriding:
http://msdn.microsoft.com/library/de...us/vbcn7/html/ vaconoverriding existingmethods .asp
To change the signature, you will have to use the Overloads keyword.
hope that helps..
Imran.
"Amin Sobati" <am***@morva.ne t> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. Hi,
I have two classes. Class2 inhertis Class1:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()
End Sub
End Class
Public Class Class2
Inherits Class1
Public Overrides Sub MySub()
End Sub
End Class
-----------------------------
When I write MySub with another signature in Class1, MySub in Class2
becomes underlined and indicates an error:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()
End Sub
Public Overridable Sub MySub(ByVal i As Int16)
End Sub
End Class
Public Class Class2
Inherits Class1
Public Overrides Sub MySub()
End Sub
End Class
-----------------------------
I know that I can fix it by adding Overloads keyword to MySub in
Class2, but I want to know the reason that why it's not possible to override it
without overloading?
Any help would be greatly appreciated.
Amin