【发布时间】:2012-08-31 09:09:49
【问题描述】:
我有以下 C++/CLI 类:
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# c++-cli operator-overloading