我使用operator *取消引用我的C ++ / CLI类中的指针,编译器会发出有关此操作的警告:
C4383: 'instance_dereference_operator' : the meaning of dereferencing a handle can change, when a user-defined 'operator' operator exists; write the operator as a static function to be explicit about the operand
如何避免此警告?这是代码:
ref struct MyClass
{
// ...
T& operator*()
{
return *m_pValue;
}
// ...
}
答案 0 :(得分:0)
最后,我实现了静态运算符重载,因为@ hans-passant建议:
static T& operator*(MyClass %obj)
{
return *obj.GetActualValue();
}