473,707 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overloads Overrides

Hi
I am here to solve a small confusion i have in "Overloads Overrides".

"Overloadin g" 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?

How we can implement both of these all at the same time like

[Visual Basic.NET]
Overloads Overrides Public Sub DoSomething()

Here, if we change the signature we can't implement Overriding and if
we don't change signature then we can't implement Overloading BUT It
is happening. How?
Has VB.NET changed the concept of overloading and overriding or
I AM WRONG :(: ?

Ref:
http://msdn.microsoft.com/library/de...elinetopic.asp

Would someone make it clear how this is being done.
Thanks
Nov 21 '05 #1
10 13788
Atif,
Overloads Overrides Public Sub DoSomething() Says that you are overriding MyBase.DoSometh ing() with no parameters, while
a MyBase.DoSometh ing(...) or MyClass.DoSomet hing(...) with parameters
exists.

Hope this helps
Jay

"Atif" <at*******@hotm ail.com> wrote in message
news:3c******** *************** ***@posting.goo gle.com... Hi
I am here to solve a small confusion i have in "Overloads Overrides".

"Overloadin g" 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?

How we can implement both of these all at the same time like

[Visual Basic.NET]
Overloads Overrides Public Sub DoSomething()

Here, if we change the signature we can't implement Overriding and if
we don't change signature then we can't implement Overloading BUT It
is happening. How?
Has VB.NET changed the concept of overloading and overriding or
I AM WRONG :(: ?

Ref:
http://msdn.microsoft.com/library/de...elinetopic.asp

Would someone make it clear how this is being done.
Thanks

Nov 21 '05 #2
Jay B. Harlow [MVP - Outlook] wrote:
Atif,
Overloads Overrides Public Sub DoSomething()


Says that you are overriding MyBase.DoSometh ing() with no parameters, while
a MyBase.DoSometh ing(...) or MyClass.DoSomet hing(...) with parameters
exists.


The compiler does not agree with you:

Public Class Foo
Public Overrides Function Equals(ByVal other As Object) As Boolean
End Function
End Class

The compiler issues the following warning for this code:

warning BC40003: function 'Equals' shadows an overloadable member declared in
the base class 'Object'. If you want to overload the base method, this method
must be declared 'Overloads'.

The only Equals() methods that are involved are the ones on System.Object and Foo,
and no Equals() with different parameters exists.

Yet, I get the warning unless I write:

Public Overloads Function Equals(ByVal other As Object) As Boolean

However, I'm not overloading Equals, I'm overriding it: the function signature
in the derived class matches the function signature in the base class.

Another way to get rid of the warning is to use:

Public Overloads Overrides Function Equals(ByVal other As Object) As Boolean

But, again, I'm not overloading anything, I'm overriding the base class method.

It seems that the compiler is in conflict with the documentation, which says:

Overloads
Optional. Indicates that this Function procedure overloads one or more
procedures defined with the same name in a base class. The argument list
in this declaration must be different from the argument list of every
overloaded procedure. The lists must differ in the number of arguments,
their data types, or both. This allows the compiler to distinguish which
version to use.

Overrides
Optional. Indicates that this Function procedure overrides an identically
named procedure in a base class. The number and data types of the arguments,
and the data type of the return value, must exactly match those of the base
class procedure.

So, overloading does not apply in case of Equals, yet the compiler issues the warning
unless the Overloads keyword is present. Seems that the compiler needs fixing?

Cheers,

Michi.
Nov 21 '05 #3
Jay
Overloads Overrides Public Sub DoSomething()
Says that you are overriding MyBase.DoSometh ing() with no parameters, while
a MyBase.DoSometh ing(...) or MyClass.DoSomet hing(...) with parameters
exists.


Let us suppose these three methods are there in MyBase
1- DoSomething()
2- DoSomething(a as integer)
3- DoSomething(a as integer, b as integer)

If you write
Overrides Public Sub DoSomething(a as integer)
you are specifying exactly which method you are overriding i.e. 2nd,
no need to add Overloads as there is no overloading
Michi
The compiler does not agree with you:
. . . Seems that the compiler needs fixing?


I agree, but, we require more comments
Nov 21 '05 #4
Michi,
System.Object has overloaded Equals.

http://msdn.microsoft.com/library/de...qualsTopic.asp

Overloads Public Overridable Function Equals(Object) As Boolean
Overloads Public Shared Function Equals(Object, Object) As Boolean
Hence the error, and hence the need for the Overloads keyword.

Hope this helps
Jay

"Michi Henning" <mi***@zeroc.co m> wrote in message
news:41******** ******@zeroc.co m...
Jay B. Harlow [MVP - Outlook] wrote:
Atif,
Overloads Overrides Public Sub DoSomething()


Says that you are overriding MyBase.DoSometh ing() with no parameters,
while a MyBase.DoSometh ing(...) or MyClass.DoSomet hing(...) with
parameters exists.


The compiler does not agree with you:

Public Class Foo
Public Overrides Function Equals(ByVal other As Object) As Boolean
End Function
End Class

The compiler issues the following warning for this code:

warning BC40003: function 'Equals' shadows an overloadable member
declared in
the base class 'Object'. If you want to overload the base method, this
method
must be declared 'Overloads'.

The only Equals() methods that are involved are the ones on System.Object
and Foo,
and no Equals() with different parameters exists.

Yet, I get the warning unless I write:

Public Overloads Function Equals(ByVal other As Object) As Boolean

However, I'm not overloading Equals, I'm overriding it: the function
signature
in the derived class matches the function signature in the base class.

Another way to get rid of the warning is to use:

Public Overloads Overrides Function Equals(ByVal other As Object) As
Boolean

But, again, I'm not overloading anything, I'm overriding the base class
method.

It seems that the compiler is in conflict with the documentation, which
says:

Overloads
Optional. Indicates that this Function procedure overloads one or more
procedures defined with the same name in a base class. The argument list
in this declaration must be different from the argument list of every
overloaded procedure. The lists must differ in the number of arguments,
their data types, or both. This allows the compiler to distinguish which
version to use.

Overrides
Optional. Indicates that this Function procedure overrides an identically
named procedure in a base class. The number and data types of the
arguments,
and the data type of the return value, must exactly match those of the
base
class procedure.

So, overloading does not apply in case of Equals, yet the compiler issues
the warning
unless the Overloads keyword is present. Seems that the compiler needs
fixing?

Cheers,

Michi.

Nov 21 '05 #5
Atif,
If you write
Overrides Public Sub DoSomething(a as integer)
you are specifying exactly which method you are overriding i.e. 2nd,
no need to add Overloads as there is no overloading Correct, you are specifying exactly which method you are overriding.

HOWEVER!!! you are also overloading base #1 & base #3! With out the
Overloads on your derived #2, the compiler will assume you wanted to Shadow
base #1 & base #3 when you shadow #1 & #3 they are not available from
variables of your derived class...

Hope this helps
Jay
"Atif" <at*******@hotm ail.com> wrote in message
news:3c******** *************** **@posting.goog le.com... Jay
>>Overloads Overrides Public Sub DoSomething()
>
> Says that you are overriding MyBase.DoSometh ing() with no parameters,
> while
> a MyBase.DoSometh ing(...) or MyClass.DoSomet hing(...) with parameters
> exists.


Let us suppose these three methods are there in MyBase
1- DoSomething()
2- DoSomething(a as integer)
3- DoSomething(a as integer, b as integer)

If you write
Overrides Public Sub DoSomething(a as integer)
you are specifying exactly which method you are overriding i.e. 2nd,
no need to add Overloads as there is no overloading
Michi
The compiler does not agree with you:
. . . Seems that the compiler needs fixing?


I agree, but, we require more comments

Nov 21 '05 #6
Jay B. Harlow [MVP - Outlook] wrote:
Michi,
System.Object has overloaded Equals.

http://msdn.microsoft.com/library/de...qualsTopic.asp

Overloads Public Overridable Function Equals(Object) As Boolean
Overloads Public Shared Function Equals(Object, Object) As Boolean
Hence the error, and hence the need for the Overloads keyword.


Ah, that makes sense. Thanks for that!

Cheers,

Michi.
Nov 21 '05 #7
Jay B. Harlow [MVP - Outlook] wrote:
Michi,
System.Object has overloaded Equals.

http://msdn.microsoft.com/library/de...qualsTopic.asp

Overloads Public Overridable Function Equals(Object) As Boolean
Overloads Public Shared Function Equals(Object, Object) As Boolean
Hence the error, and hence the need for the Overloads keyword.


Ah, that makes sense. Thanks for that!

Cheers,

Michi.
Nov 21 '05 #8
> HOWEVER!!! you are also overloading base #1 & base #3! With out the
Overloads on your derived #2, the compiler will assume you wanted to Shadow
base #1 & base #3 when you shadow #1 & #3 they are not available from
variables of your derived class...


GOT IT :)
Thanks, Thanks alot
Nov 21 '05 #9
> HOWEVER!!! you are also overloading base #1 & base #3! With out the
Overloads on your derived #2, the compiler will assume you wanted to Shadow
base #1 & base #3 when you shadow #1 & #3 they are not available from
variables of your derived class...


GOT IT :)
Thanks, Thanks alot
Nov 21 '05 #10

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

Similar topics

12
1739
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)
2
2656
by: Dot net work | last post by:
Hello, My simple code is here: Public Class MyDictionary Inherits System.Collections.DictionaryBase Private Class MyElement Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean End Function
3
1746
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
12
2390
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.
2
6577
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...
0
1030
by: Internet User | last post by:
According to MSDN, You should never base the security of your application on a member that is marked with the internal virtual modifier in C# (the Overloads Overridable Friend modifier in Visual Basic). Although members marked with these modifiers can only be overridden by other members within the current assembly, this rule is enforced only by the C# and Visual Basic languages. The runtime does not enforce this rule. It is therefore...
5
1404
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 ?
0
8787
marktang
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...
0
9158
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9060
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,...
0
9001
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
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3151
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
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2096
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.