473,583 Members | 2,875 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 13781
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
1736
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
2645
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
1741
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
2380
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
6551
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,...
0
1024
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...
5
1394
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
8159
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8314
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...
1
7922
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...
0
6571
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3811
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...
0
3836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2317
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
1
1416
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
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...

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.