我正在 Xcode 中开发一个 cocos2d 项目,并且我一直在尝试让碰撞检测工作数周。我一直在使用 Ray Wenderlich 教程,该教程说使用接触侦听器来检测碰撞。但是,我收到错误Invalid operands to binary expression ('const MyContact' and 'const MyContact')。我从来没有见过这个错误,有人可以帮忙吗?
#import "MyContactListener.h"
MyContactListener::MyContactListener() : _contacts() {
}
MyContactListener::~MyContactListener() {
}
void MyContactListener::BeginContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
_contacts.insert(myContact); <------------//Says "7.In instantiation of member function 'std::set<MyContact, std::less<MyContact>, std::allocator<MyContact> >::insert' requested here"
}
void MyContactListener::EndContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
std::set<MyContact>::iterator pos;
pos = std::find(_contacts.begin(), _contacts.end(), myContact);
if (pos != _contacts.end()) {
_contacts.erase(pos);
}
}
void MyContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) {
}
void MyContctListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) {
}