473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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,MCAD
------------------------------

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 1198
| 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)...and 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******@2k1soft.com> wrote in message
news:ub*************@TK2MSFTNGP11.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,MCAD
------------------------------

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******@2k1soft.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
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) ...
5
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...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
12
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...
10
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...
4
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...
3
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...
5
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.