4
我有下面的C++/CLI類:C++/CLI重載運營商不通過C#訪問
public ref class MyClass
{
public:
int val;
bool operator==(MyClass^ other)
{
return this->val == other->val;
}
bool Equals(MyClass^ other)
{
return this == other;
}
};
當我嘗試從C#的MyClass
兩個實例是否相等,我得到一個錯誤的結果來驗證:
MyClass a = new MyClass();
MyClass b = new MyClass();
//equal1 is false since the operator is not called
bool equal1 = a == b;
//equal2 is true since the comparison operator is called from within C++\CLI
bool equal2 = a.Equals(b);
我在做什麼錯了?
[如何在C++/CLI應用程序中修復警告CA2226?](http://stackoverflow.com/questions/4589426/how-to-fix-warning-ca2226-in-ac-cli-application ) –