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 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?
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
"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
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!
"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 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: 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
|
by: Michael C |
last post by:
eg
void DoIt()
{
int i = FromString("1");
double d = FromString("1.1");
}
int FromString(string SomeValue)
{
|
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)
|
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: 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: 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 ?
|
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
|
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: 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: 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...
| |