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
Nov 20 '05
12 1751
Jay: 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!
I don't mind adding the Overloads keyword; and I don't want to beat this to
death or be dense -- but I do want to understand...
My base and derived classes each have a single Item property; so it's not
overloaded in either. You state that if I add an overloaded Item to my base I
still won't have one in my derived class. I agree; but I don't see how that's
different than the way my Remove methods are currently declared -- the base
class has an overloaded method and the derived class overrides only one of them.
Well, I just tried overloading the Item property in my base class and the Item
declaration in my derived class got flagged as needing Overloads. I then tried
overriding both properties in the derived class and both declaration got
flagged. So it seems that when a method/property is (implicitly) overloaded in
the base class it must be explicitly overloaded in the derived class. I guess I
don't see why the Overrides keyword isn't sufficient.
--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com
Facilitating the automated conversion of Data into Information
since 1982
Lee, My base and derived classes each have a single Item property; so it's not overloaded in either. You state that if I add an overloaded Item to my
base I still won't have one in my derived class. I agree; but I don't see how
that's different than the way my Remove methods are currently declared --
Its a versioning thing. ;-) Mostly when you are deriving from class library
classes.
Java for example does it the other way. In Java when you add an overload in
the base any derived classes automatically gain the overload, this has known
to cause problems occasional. The .NET designers decided rather then allow
these potential problems to Shadow by default rather then overload by
default. Of course this may cause other problems, its a tradeoff either
way...
Also you are assuming that the derived class is going to be compiled, what
happens when derived class is already compiled? I can compile an assembly
under version 1.0 of a class library, and run it under version 2.0 of a
class library without recompiling my original assembly...
NOTE: Think of your MainForm class overriding a method in Microsoft's Form
class. When you upgrade to .NET 2.0 if Microsoft added an overload to that
method in the Form class, this may cause problems in your derived class. To
minimize these problems, the default is to Shadow, hence the warning.
different than the way my Remove methods are currently declared -- the
base class has an overloaded method and the derived class overrides only one of
them.
That's the point! your derived class overrides only one of them. You only
get one of them in the derived class unless you add Overloads!
Again refer to my overload example, when you use intellisense on the
underlord variable, how many Remove methods are listed? How many are listed
for the overlord variable?
Hope this helps
Jay
"Lee Silver" <LS*****@inform ation-concepts.com> wrote in message
news:aa******** *************** ***@msgid.megan ewsservers.com. .. Jay:
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!
I don't mind adding the Overloads keyword; and I don't want to beat this
to death or be dense -- but I do want to understand...
My base and derived classes each have a single Item property; so it's not overloaded in either. You state that if I add an overloaded Item to my
base I still won't have one in my derived class. I agree; but I don't see how
that's different than the way my Remove methods are currently declared -- the
base class has an overloaded method and the derived class overrides only one of
them. Well, I just tried overloading the Item property in my base class and the
Item declaration in my derived class got flagged as needing Overloads. I then
tried overriding both properties in the derived class and both declaration got flagged. So it seems that when a method/property is (implicitly)
overloaded in the base class it must be explicitly overloaded in the derived class. I
guess I don't see why the Overrides keyword isn't sufficient.
-- // Lee Silver // Information Concepts Inc. // http://www.information-concepts.com
Facilitating the automated conversion of Data into Information since 1982
Jay:
I think I got it now. Thanks for your patience in explaining it.
--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com
Facilitating the automated conversion of Data into Information
since 1982 Java for example does it the other way. In Java when you add an overload in the base any derived classes automatically gain the overload, this has known to cause problems occasional. The .NET designers decided rather then allow these potential problems to Shadow by default rather then overload by default. Of course this may cause other problems, its a tradeoff either way...
Also you are assuming that the derived class is going to be compiled, what happens when derived class is already compiled? I can compile an assembly under version 1.0 of a class library, and run it under version 2.0 of a class library without recompiling my original assembly...
NOTE: Think of your MainForm class overriding a method in Microsoft's Form class. When you upgrade to .NET 2.0 if Microsoft added an overload to that method in the Form class, this may cause problems in your derived class. To minimize these problems, the default is to Shadow, hence the warning. 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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |