Home All Groups Group Topic Archive Search About

Can't Override Equals in .NET 1.1 using VB

Author
20 Dec 2006 7:40 PM
Gunnar Valur
Hi,

I am trying to override the Equals function in Object with VB 2003 (.NET
1.1) like this:

Public Class Foo
    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        Return True
    End Function
End Class

Visual Basic however gives me the following error:

"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'."

This is very strange since Equals is defined as overridable and has exactly
the same prototype in Object.

Is this a bug in VB? Because this works fine in C# 2003 and in VB 2005.

Author
21 Dec 2006 10:22 AM
Phill W.
Gunnar Valur wrote:

> Visual Basic however gives me the following error:
>
> "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'."
>
> This is very strange since Equals is defined as overridable and has exactly
> the same prototype in Object.
>
> Is this a bug in VB? Because this works fine in C# 2003 and in VB 2005.

More of a "feature" - There are two overloads for Object.Equals; the one
you're trying to override and the Shared version that compares two,
explicitly supplied Objects.  /I think/ that because these two, supplied
methods are declared as "Overloads", any Overrides that you write /also/
have to be declared as "Overloads", even though you don't actually care.

HTH,
    Phill  W.

Show quoteHide quote
>
Author
21 Dec 2006 10:59 AM
Gunnar Valur
Thanks Phill,

Had just forgotten how illogical VB can sometimes be.  At least this is
fixed in VB 2005