473,498 Members | 2,058 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".

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

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 13760
Atif,
Overloads Overrides Public Sub DoSomething() Says that you are overriding MyBase.DoSomething() with no parameters, while
a MyBase.DoSomething(...) or MyClass.DoSomething(...) with parameters
exists.

Hope this helps
Jay

"Atif" <at*******@hotmail.com> wrote in message
news:3c**************************@posting.google.c om... 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?

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.DoSomething() with no parameters, while
a MyBase.DoSomething(...) or MyClass.DoSomething(...) 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.DoSomething() with no parameters, while
a MyBase.DoSomething(...) or MyClass.DoSomething(...) 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.com> wrote in message
news:41**************@zeroc.com...
Jay B. Harlow [MVP - Outlook] wrote:
Atif,
Overloads Overrides Public Sub DoSomething()


Says that you are overriding MyBase.DoSomething() with no parameters,
while a MyBase.DoSomething(...) or MyClass.DoSomething(...) 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*******@hotmail.com> wrote in message
news:3c*************************@posting.google.co m... Jay
>>Overloads Overrides Public Sub DoSomething()
>
> Says that you are overriding MyBase.DoSomething() with no parameters,
> while
> a MyBase.DoSomething(...) or MyClass.DoSomething(...) 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
Ok,
If you have overloaded a method of the base class in your class and
then you are Overriding any overloaded version of that method, either
in your class or in the base class, you have to use both Overloads
Overrides.

Why do this?

As far as Shadowing is concern if i don't use Overloads(in Overloads
Overrides), I am clearly specifying that i am Overriding the methos.
If i ommit both the words(Overloads Overrides) then it will shadow the
method in base class otherwise it shouldn't.

How VB.NET's Compiler implements these concepts(as far as calling a
nethod is concern) i.e. u should use Overloads otherwise it will
shadow....if not overloading the method then can use Overrides
otherwise should use Overloads Overrides.... :)):

Any help = appreciated^2
Nov 21 '05 #11

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

Similar topics

12
1719
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...
2
2633
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)...
3
1727
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...
12
2371
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...
2
6538
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...
0
1017
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...
5
1388
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...
0
7121
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,...
0
6993
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...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7375
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...
0
5456
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,...
0
4584
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
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 ...
0
287
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...

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.