Re: Overriding my method
From: Amin Sobati (amins_at_morva.net)
Date: 09/02/04
- Next message: Moondog: "Re: How do I get the column index of a datagrid from the column title?"
- Previous message: _IS_ -: "Re: vb vs vb.net"
- In reply to: Imran Koradia: "Re: Overriding my method"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 2 Sep 2004 23:04:49 +0430
Imran,
The first code you wrote has the same problem. Overloads keyword does not
solve the problem and the code did not compile. You must include Overloads
keyword in class2.
Amin
"Imran Koradia" <nospam@microsoft.com> wrote in message
news:ObZrhzCkEHA.2680@TK2MSFTNGP15.phx.gbl...
> 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" <amins@morva.net> wrote in message
> news:%23nMPkjCkEHA.1900@TK2MSFTNGP10.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" <nospam@microsoft.com> wrote in message
> > news:#n5FUJCkEHA.2652@TK2MSFTNGP15.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/default.asp?url=/library/en-us/vbcn7/html/
> > vaconoverridingexistingmethods.asp
> > >
> > > To change the signature, you will have to use the Overloads keyword.
> > >
> > > hope that helps..
> > > Imran.
> > >
> > > "Amin Sobati" <amins@morva.net> wrote in message
> > > news:%23cbZlT$jEHA.3848@tk2msftngp13.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
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: Moondog: "Re: How do I get the column index of a datagrid from the column title?"
- Previous message: _IS_ -: "Re: vb vs vb.net"
- In reply to: Imran Koradia: "Re: Overriding my method"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|