Search code examples
c++xcode4box2d

set a c++ class nil in xcode ".mm" file.


In somebody's project I found a error. I know it is wrong. But it works well.

in .mm file do like this

- (void) DestroySelfBody{
    [self unschedule:@selector(DestroySelfBody)];
    if (m_body) {
        m_body->GetWorld()->DestroyBody(m_body);
        m_body = nil;
    }
}

m_body is define by (b2Body is a c++ class):

b2Body * m_body;

Solution

  • Use nullptr for C++ types: m_body = nullptr;.