Code Scraps from the Attic

Every so often I get an error message from the compiler that stumps me.  After searching online and trying various tweaks I end up writing a simplified test only to find out if something I though was possible really is not possible.  In this case it was interface inheritance using IEquatable<T>.

I created this example a month or so ago and stashed it away intending to write a blog post about it.  Unfortunately I fogot what the point of the post was going to be, so instead I present it to you as is for your amusement.


interface class IInt : System::IEquatable<IInt^>
    {
    property int Integer {int get();}
    };

ref class Test : IInt
    {
private:
     int m_i;
public:
    Test (int i) : m_i (i) {}
    virtual System::String^ ToString() override {return System::String::Format ("{0}", m_i);}
    virtual bool Equals (IInt^ t) {return t->Integer == m_i;}
    virtual property int Integer {int get() {return m_i;}}
    };

void test ()
     {
     IInt^ a = gcnew Test(1);
     IInt^ b = gcnew Test(2)
     if (a->Equals(b))
     return;
     }

The above code generates error C2385: ambiguous access of 'Equals' could be the 'Equals' in base 'System::IEquatable<IInt ^>' or could be the 'Equals' in base 'System::Object'