In a base class I have the following 2 declarations:
Overridable Sub Remove(ByVal wIndex As Integer)
and
Overridable Sub Remove(ByVal wValue As Object)
In an immediately derived class I have the following declaration:
Overloads Overrides Sub Remove(ByVal wIndex As Integer)
Why is Overloads needed in the derived class? Without it intellisense tells me
"Remove shadows an overloadable method in the base class. If you want to
overload the base method this method must be declared Overloads?" Since the
signatures of the 2 methods are the same, I would think the compiler could
determine that the derived method is overriding the Remove(Integer) vs
Remove(Object). What am I missing?
Is it accurate to deduce, based on the intellisense message, that if Remove
weren't overloaded in the base cass I wouldn't need Overloads in the derived one?
--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com
Facilitating the automated conversion of Data into Information
since 1982 12 1748
Hi Lee,
Probably you are right, however VB.net is full of this kind of things which
seems to be adepted from C.
Another thing in this is that you have to cast a lot of things which can
only be casted one way because the accepting value/object only accept that
object/value.
However promished is in the next version a kind of spellchecker, which
corrects that.
(It is not completly dumb, it checks of course if you are not by accident
using an existing method which is by some methods very clear however with
others very unclear).
An example from what I find dump
dim A as integer = CInt(2/2)
Cor
* Lee Silver <LS*****@inform ation-concepts.com> scripsit: In a base class I have the following 2 declarations:
Overridable Sub Remove(ByVal wIndex As Integer) and
Overridable Sub Remove(ByVal wValue As Object)
In an immediately derived class I have the following declaration:
Overloads Overrides Sub Remove(ByVal wIndex As Integer)
Why is Overloads needed in the derived class? Without it intellisense tells me "Remove shadows an overloadable method in the base class. If you want to overload the base method this method must be declared Overloads?" Since the signatures of the 2 methods are the same, I would think the compiler could determine that the derived method is overriding the Remove(Integer) vs Remove(Object). What am I missing?
It's not for the compiler, it's for the person who reads the code. More
info can be found by setting the caret onto 'Overloads' and pressing the
F1 key.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Herfried: It's not for the compiler, it's for the person who reads the code. More info can be found by setting the caret onto 'Overloads' and pressing the F1 key.
I had previously F1'd on Overloads, and the explanation didn't help me :). I
would think that the Overrides' would tell the reader of the code that there is
an identically named/signed function in the parent class.
Quoting from the 'about Overloads keyword': "The Overloads keyword declares a
property or method with the same name as an existing member, but with an
argument list different from the original member." I don't think this applies
because the methods have the same argument list (unless the compiler somehow
can't tell which method is being overridden).
Therefore I'm thinking this paragraph applies: "Overloads can also be used to
shadow an existing member, or set of overloaded members, in a base class. When
you use Overloads in this way, you declare the property or method with the same
name and the same argument list as the base class member, and you do not supply
the Shadows keyword."
It would seem from this that I don't need Overridable in the base class and
Overrides in the derived class -- just Shadows in the derived class. Then why
have Overridable and Overrides if I also need Overloads? I'm missing something,
but I don't know what; because to me, Overriding isn't the same as Shadowing
(the former has identical arguments and the latter doesn't).
--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com
Facilitating the automated conversion of Data into Information
since 1982
Lee,
In addition to the other comments:
Overloads is needed so the compiler will know if Sub Remove(Object) will be
available via your derived class!
Consider the following:
Option Strict On
Public Class Base
Public Overridable Sub Remove(ByVal wIndex As Integer)
End Sub
Public Overridable Sub Remove(ByVal wValue As Object)
End Sub
Public Sub Main()
Dim overlord As New OverloadedBase
overlord.Remove (10)
overlord.Remove ("Jay")
Dim underlord As New ShadowsBase
underlord.Remov e(10)
underlord.Remov e("Jay")
End Sub
End Class
Public Class OverloadedBase
Inherits Base
Public Overloads Overrides Sub Remove(ByVal wIndex As Integer)
End Sub
End Class
Public Class ShadowsBase
Inherits Base
Public Overrides Sub Remove(ByVal wIndex As Integer)
End Sub
End Class
The underload.Remov e("Jay") method has an error, because you forgot to
include Overloads, so Shadows was implicitly used. Shadows causes
Base.Remove(Obj ect) to be hidden in OverloadedBase set of methods. Without
the Option Strict On, VB.NET will attempt to convert "jay" to an integer at
run time on the underload.Remov e("Jay") line.
Shadows is used for versioning, so methods added to version 2 of classes
don't suddenly cause surprises in classes that were designed for version 1
of the base class.
NOTE: Shadows base can be written as:
Public Class ShadowsBase
Inherits Base
Public Shadows Overrides Sub Remove(ByVal wIndex As Integer)
End Sub
End Class
Which will remove the warning about adding either Shadows or Overloads.
Hope this helps
Jay
"Lee Silver" <LS*****@inform ation-concepts.com> wrote in message
news:7f******** *************** ****@msgid.mega newsservers.com ... In a base class I have the following 2 declarations:
Overridable Sub Remove(ByVal wIndex As Integer) and
Overridable Sub Remove(ByVal wValue As Object)
In an immediately derived class I have the following declaration:
Overloads Overrides Sub Remove(ByVal wIndex As Integer)
Why is Overloads needed in the derived class? Without it intellisense
tells me "Remove shadows an overloadable method in the base class. If you want to overload the base method this method must be declared Overloads?" Since
the signatures of the 2 methods are the same, I would think the compiler could determine that the derived method is overriding the Remove(Integer) vs Remove(Object). What am I missing?
Is it accurate to deduce, based on the intellisense message, that if
Remove weren't overloaded in the base cass I wouldn't need Overloads in the
derived one? -- // Lee Silver // Information Concepts Inc. // http://www.information-concepts.com
Facilitating the automated conversion of Data into Information since 1982
* Lee Silver <LS*****@inform ation-concepts.com> scripsit:
[...]
Have a look at Jay's explanation... I should really take more sleep.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Addendum:
MSDN says:
<msdn>
Overloads can also be used to shadow an existing member, or set of
overloaded members, in a base class. When you use Overloads in this way,
you declare the property or method with the same name and the same
argument list as the base class member, and you do not supply the
Shadows keyword.
</msdn>
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Doh!
Ignore this part, it causes a compile error: NOTE: Shadows base can be written as:
Public Class ShadowsBase Inherits Base
Public Shadows Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
Which will remove the warning about adding either Shadows or Overloads.
However what I show in the above is effectively what is happening when you
don't use Overloads.
Hope this helps
Jay
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:O8******** ******@TK2MSFTN GP11.phx.gbl... Lee, In addition to the other comments:
Overloads is needed so the compiler will know if Sub Remove(Object) will
be available via your derived class!
Consider the following:
Option Strict On
Public Class Base
Public Overridable Sub Remove(ByVal wIndex As Integer)
End Sub
Public Overridable Sub Remove(ByVal wValue As Object)
End Sub
Public Sub Main() Dim overlord As New OverloadedBase overlord.Remove (10) overlord.Remove ("Jay")
Dim underlord As New ShadowsBase underlord.Remov e(10) underlord.Remov e("Jay") End Sub
End Class
Public Class OverloadedBase Inherits Base
Public Overloads Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
Public Class ShadowsBase Inherits Base
Public Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
The underload.Remov e("Jay") method has an error, because you forgot to include Overloads, so Shadows was implicitly used. Shadows causes Base.Remove(Obj ect) to be hidden in OverloadedBase set of methods. Without the Option Strict On, VB.NET will attempt to convert "jay" to an integer
at run time on the underload.Remov e("Jay") line.
Shadows is used for versioning, so methods added to version 2 of classes don't suddenly cause surprises in classes that were designed for version 1 of the base class.
NOTE: Shadows base can be written as:
Public Class ShadowsBase Inherits Base
Public Shadows Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
Which will remove the warning about adding either Shadows or Overloads.
Hope this helps Jay
"Lee Silver" <LS*****@inform ation-concepts.com> wrote in message news:7f******** *************** ****@msgid.mega newsservers.com ... In a base class I have the following 2 declarations:
Overridable Sub Remove(ByVal wIndex As Integer) and
Overridable Sub Remove(ByVal wValue As Object)
In an immediately derived class I have the following declaration:
Overloads Overrides Sub Remove(ByVal wIndex As Integer)
Why is Overloads needed in the derived class? Without it intellisense tells me "Remove shadows an overloadable method in the base class. If you want to overload the base method this method must be declared Overloads?" Since the signatures of the 2 methods are the same, I would think the compiler
could determine that the derived method is overriding the Remove(Integer) vs Remove(Object). What am I missing?
Is it accurate to deduce, based on the intellisense message, that if Remove weren't overloaded in the base cass I wouldn't need Overloads in the derived one? -- // Lee Silver // Information Concepts Inc. // http://www.information-concepts.com
Facilitating the automated conversion of Data into Information since 1982
Jay:
Aha, I think I got it -- the key phrase is "Shadows is used for versioning".
Without Overloads, Shadows would be required; and since neither is implied I
need to specify Overloads.
But this brings up something interesting... In my Base class I have a
non-overloaded overridable property, Item. In my derived class I declare it
Overrides, without Overloads or Shadows, and it compiles just fine. If at some
point in the future I modify Base class to overload Item, won't that break my
derived class?
--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com
Facilitating the automated conversion of Data into Information
since 1982 Lee, In addition to the other comments:
Overloads is needed so the compiler will know if Sub Remove(Object) will be available via your derived class!
Consider the following:
Option Strict On
Public Class Base
Public Overridable Sub Remove(ByVal wIndex As Integer)
End Sub
Public Overridable Sub Remove(ByVal wValue As Object)
End Sub
Public Sub Main() Dim overlord As New OverloadedBase overlord.Remove (10) overlord.Remove ("Jay")
Dim underlord As New ShadowsBase underlord.Remov e(10) underlord.Remov e("Jay") End Sub
End Class
Public Class OverloadedBase Inherits Base
Public Overloads Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
Public Class ShadowsBase Inherits Base
Public Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
The underload.Remov e("Jay") method has an error, because you forgot to include Overloads, so Shadows was implicitly used. Shadows causes Base.Remove(Obj ect) to be hidden in OverloadedBase set of methods. Without the Option Strict On, VB.NET will attempt to convert "jay" to an integer at run time on the underload.Remov e("Jay") line.
Shadows is used for versioning, so methods added to version 2 of classes don't suddenly cause surprises in classes that were designed for version 1 of the base class.
NOTE: Shadows base can be written as:
Public Class ShadowsBase Inherits Base
Public Shadows Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
Which will remove the warning about adding either Shadows or Overloads.
Hope this helps Jay
Lee,
You example is largely the reason VB.NET defaults to Shadows.
Your derived class currently does not have an overloaded Item property, if
you add an overloaded Item property to the base. Your derived class still
will not have an overloaded Item property!
You will need to visit your derived class and decide if you want the
overloaded Item in your derived class also...
Hope this helps
Jay
"Lee Silver" <LS*****@inform ation-concepts.com> wrote in message
news:33******** *************** ***@msgid.megan ewsservers.com. .. Jay:
Aha, I think I got it -- the key phrase is "Shadows is used for
versioning". Without Overloads, Shadows would be required; and since neither is implied
I need to specify Overloads.
But this brings up something interesting... In my Base class I have a non-overloaded overridable property, Item. In my derived class I declare
it Overrides, without Overloads or Shadows, and it compiles just fine. If at
some point in the future I modify Base class to overload Item, won't that break
my derived class?
-- // Lee Silver // Information Concepts Inc. // http://www.information-concepts.com
Facilitating the automated conversion of Data into Information since 1982
Lee, In addition to the other comments:
Overloads is needed so the compiler will know if Sub Remove(Object) will
be available via your derived class!
Consider the following:
Option Strict On
Public Class Base
Public Overridable Sub Remove(ByVal wIndex As Integer)
End Sub
Public Overridable Sub Remove(ByVal wValue As Object)
End Sub
Public Sub Main() Dim overlord As New OverloadedBase overlord.Remove (10) overlord.Remove ("Jay")
Dim underlord As New ShadowsBase underlord.Remov e(10) underlord.Remov e("Jay") End Sub
End Class
Public Class OverloadedBase Inherits Base
Public Overloads Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
Public Class ShadowsBase Inherits Base
Public Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
The underload.Remov e("Jay") method has an error, because you forgot to include Overloads, so Shadows was implicitly used. Shadows causes Base.Remove(Obj ect) to be hidden in OverloadedBase set of methods.
Without the Option Strict On, VB.NET will attempt to convert "jay" to an integer
at run time on the underload.Remov e("Jay") line.
Shadows is used for versioning, so methods added to version 2 of classes don't suddenly cause surprises in classes that were designed for version
1 of the base class.
NOTE: Shadows base can be written as:
Public Class ShadowsBase Inherits Base
Public Shadows Overrides Sub Remove(ByVal wIndex As Integer) End Sub
End Class
Which will remove the warning about adding either Shadows or Overloads.
Hope this helps Jay This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: valamas |
last post by:
Hi All
How can I recode the following so that I do not repeat my
code?
Public Overloads Sub SetNodeImageIndex(ByVal oNode As
System.Windows.Forms.TreeNode, ByVal ImageIndex As String)
oNode.ImageIndex = ImageIndex
oNode.SelectedImageIndex = ImageIndex
|
by: Michael C |
last post by:
eg
void DoIt()
{
int i = FromString("1");
double d = FromString("1.1");
}
int FromString(string SomeValue)
{
|
by: Atif |
last post by:
Hi
I am here to solve a small confusion i have in "Overloads Overrides".
"Overloading" says that the method's name should be same while no. of
parameters and/or their datatypes should be changed either in the same
class or inherited class. right?
"Overriding" says that the method's signature should be same(name,no.
of parameters and their datatypes) in the inherited class while
implementation may change. right?
|
by: Laurent Allardin |
last post by:
Hi,
Why this code compile???
We should not be able to Override the code by using the Overloads since the
sub as exactly the same parameters....
Thank you.
Laurent Allardin,MCSD,MCAD
|
by: Gary Paris |
last post by:
Why would you use an Overloads routine instead of just putting the code in
the default routine?
Private Overloads Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim isKey As Boolean = e.KeyChar.IsDigit(e.KeyChar)
If isKey Then
| |
by: Arthur Dent |
last post by:
Hi all,
Im just curious, what is the purpose of the keyword "Overloads" in VB
nowadays?
I understand conceptually what overloads are and what they do, but im a
little puzzled,
because if you declare two subs or properties or functions with the same
name but
different signatures, it seems to overload them without any problem anyway,
so why
|
by: adsci |
last post by:
Hello!
Im posting this to c.l.c++ AND win32 because i dont know if this is a MS
Compiler Issue or not.
here we go:
<code>
class MyCString
|
by: André |
last post by:
Hi,
i'm learning working with classes.
In class "classbase1", i defined an overridable function. In the class
"subclass1", i defined the same function with 'Overrides'.
In class "classbase2", i defined the same function and in the class
"subclass2", i defined the same function with 'Overloads'.
Result: i get the same output.
|
by: =?Utf-8?B?QU1lcmNlcg==?= |
last post by:
In the class below, I inherit from Generic.Dictionary so I can override
property Item. Item is not overridable, so I used Shadows, and it works as I
want. It works equally well if I replace Shadows with Overloads.
Question 1 - Which is preferred in a case like this, Shadows or Overloads.
Question 2 - The Override clan (Overrides, Overridable, NotOverridable,
MustOverride) seems to have lost some steam if I can effect an override on...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |