I am writing a C ++ / CLI wrapper from the Cical Native Static Library.
I do not have much experience with C ++ / CLI or C ++. I followed the best practices that I read on the Internet for creating C ++ / CLI wrappers. My shell has a pointer to a C ++ class. And my C ++ is overloaded with the == operator.
I try to overload it also in my shell and use the C ++ class implementation, but I get errors when the shell is null.
I was looking for how to find out if my descriptor is null, and I found that you need to compare it with nullptr.
I have this method in C ++ / CLI
MyOtherClass const* MyClass::MyMethod(MyWrapper^ instance)
{
if(instance == nullptr)
{
return NULL;
}
return instance->Property;
}
A string if (instance == nullptr) calls my overloaded implementation of the == operator .
static bool operator==(MyWrapper^ a, MyWrapper^ b)
{
return a->InternalInstance == b->InternalInstance;
}
, a null, System.AccessViolationException.
nullptr a b, .
static bool operator==(MyWrapper^ a, MyWrapper^ b)
{
if(a == nullptr && b == nullptr)
return true;
if((a == nullptr && b != nullptr) || (a != nullptr && b == nullptr))
return false;
return a->InternalInstance == b->InternalInstance;
}
== ++ - null?