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.