Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laurent Allardin - 21 Oct 2004 18:13 GMT
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
steve - 21 Oct 2004 18:22 GMT
| 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?
Jay B. Harlow [MVP - Outlook] - 21 Oct 2004 18:57 GMT
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

> Hi,
>
[quoted text clipped - 28 lines]
>
> End Module
Larry Serflaten - 21 Oct 2004 19:06 GMT
> 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
steve - 21 Oct 2004 21:23 GMT
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!
Larry Serflaten - 22 Oct 2004 01:59 GMT
"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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.