andを実装し、 、、IEquatable<T>
およびIComparable<T>
をオーバーライドするクラスをC# から C++/CLI に移植しています。これまでのところ、私は持っています:==
!=
<
>
ヘッダ:
virtual bool Equals(Thing other);
virtual int CompareTo(Thing other);
static bool operator == (Thing tc1, Thing tc2);
static bool operator != (Thing tc1, Thing tc2);
static bool operator > (Thing tc1, Thing tc2);
static bool operator < (Thing tc1, Thing tc2);
ソースファイル:
bool Thing ::Equals(Thing other)
{
// tests equality here
}
int Thing ::CompareTo(Thing other)
{
if (this > other) // Error here
return 1;
else if (this < other)
return -1;
else
return 0;
}
bool Thing ::operator == (Thing t1, Thing t2)
{
return tc1.Equals(tc2);
}
bool Thing ::operator != (Thing t1, Thing t2)
{
return !tc1.Equals(tc2);
}
bool Thing::operator > (Thing t1, Thing t2)
{
// test for greater than
}
bool Thing::operator < (Thing t1, Thing t2)
{
// test for less than
}
オリジナルがインターフェースで同等性をテストし、オペレーターで物事を比較した理由はわかりませんが、元の構造を維持しようとしています。
とにかく、マークされた行「error C2679: binary '>' : no operator found which takes a right-hand operand of type 'ThingNamespace::Thing' (or there is no acceptable conversion)
」でコンパイルエラーが発生し、対応するエラーが2行下にあります。オーバーロードされた演算子の存在を検出しないのはなぜですか?