473,805 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

overloads - why this code compile??? Please MS answer...

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,M CAD
------------------------------

Public Class Base
Public Sub save()
Console.Write(" save base")
End Sub
End Class

Public Class Derived
Inherits Base
Public Overloads Sub save()
Console.Write(" save derived")
End Sub
End Class

Module Module1
Public Sub main()
Dim o As New derived
o.save()
End Sub

End Module
Nov 21 '05 #1
5 1243
| We should not be able to Override the code by using the Overloads since
the
| sub as exactly the same parameters....

first, overriding and overloading have nothing to do with eachother. the
former allows you to give new functionality to the base class' interface.
the latter allows polymorphism. you are not overriding the base class
interface. you should have not been able to compile though and should have
been warned to either override or shadow the derived class' matching method.
i assume the derived class' matching method definition of overload is only
amongst its members with the same name (differing parameters)...a nd not
overloading the base class.

does it complain when you try to compile without the overloads definition on
the derived class' method? what version of vb.net are you using? what
service packs are applied?
Nov 21 '05 #2
Laurent,
Why this code compile??? Why wouldn't it compile?

I agree I am as surprised as you are that it compiles, but I cannot really
come up with a good reason why it wouldn't.

In your specific sample I see Overloads as largely synonymous with Shadows,
so why disallow Overloads?

Yes Overloads & Shadows are two specific things with specific uses, however
in this instance I see them as the same thing... In other words concentric
circles and your sample is the very small overlap between the two circles...

If I have time later I will see what I can scrounge up to explain my
thinking here, no promises though.

Hope this helps
Jay

"Laurent Allardin" <la******@2k1so ft.com> wrote in message
news:ub******** *****@TK2MSFTNG P11.phx.gbl... 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,M CAD
------------------------------

Public Class Base
Public Sub save()
Console.Write(" save base")
End Sub
End Class

Public Class Derived
Inherits Base
Public Overloads Sub save()
Console.Write(" save derived")
End Sub
End Class

Module Module1
Public Sub main()
Dim o As New derived
o.save()
End Sub

End Module

Nov 21 '05 #3

"Laurent Allardin" <la******@2k1so ft.com> wrote

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....


That is called shadowing by name and signature. From the help file:

-----------
Derived classes can overload inherited members with members that have identical parameters and parameter types, a process known
as shadowing by name and signature. If the Overloads keyword is used when shadowing by name and signature, the derived classes
implementation of the member will be used instead of the implementation in the base class, and all other overloads for that
member will be available to instances of the derived class.

If the Overloads keyword is omitted when overloading an inherited member with a member that has identical parameters and
parameter types, then the overloading is called shadowing by name. Shadowing by name replaces the inherited implementation of a
member, and makes all other overloads unavailable to instances of the derived class, and its decedents.

--------------

HTH

LFS

Nov 21 '05 #4
hey larry! does your participation mean that the inevitable shove from
vb.classic to vb.net has occured? either way, good to see you here!
Nov 21 '05 #5

"steve" <a@b.com> wrote in message
hey larry! does your participation mean that the inevitable shove from
vb.classic to vb.net has occured? either way, good to see you here!


Yeah, the classics were getting a little perennial, or at least it wasn't really
providing as many new and exciting challenges as there are on this
side of the fence....

<g>
LFS

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1273
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
5
11640
by: wongjoekmeu | last post by:
Hello All, I am trying to poort a code which is written in Visual C++ 6.0 to Visual C++ in VIsual Studio .NET I receive a problem which I simply do not understand. I was wondering if anyone could help me out and explain me the problem I am receiving. I have a derive class called Mystring derived from the base std::string class. it looks like this
59
3466
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
12
1751
by: Lee Silver | last post by:
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)
10
13798
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?
4
1371
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
3
1752
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
5
1413
by: Lothar Behrens | last post by:
Hi, I have created a base class implementing an interface and a derived class also implementing the same interface. While figuring out that I am unable to call the derived method of an instance or the derived class I have added the keyword Overloads to the function. But this does not help. Why do I get these troubles ?
8
3752
by: Paul E Collins | last post by:
This code won't compile because "the modifier 'abstract' is not valid for this item". abstract class X { public abstract static bool operator >(X a, X b); public abstract static bool operator <(X a, X b); } Why is that? -- apart from the obvious reason that the specification doesn't
0
9596
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,...
0
10109
tracyyun
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...
0
9186
agi2029
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...
1
7649
isladogs
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...
0
5545
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...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
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
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.