Cocos2d-x Box2D CContactListener构造函数未定义

Xcode Linker Error Cocos2d-x Box2D CContactListener constructor undefined

本文关键字:未定义 构造函数 CContactListener Box2D Cocos2d-x      更新时间:2023-10-16

我试图让Box2D与我的Cocos2d-x项目运行。我添加了碰撞检测,但我得到了一个链接错误架构i386的未定义符号:"CContactListener::CContactListener()",引用自HelloWorldScene.o

中的:HelloWorld::init()

我已经尝试了好几种方法,研究了几天,但还是没有弄清楚。任何帮助都会很好。下面是一些代码片段

HelloWorldScene.h

 CContactListener *_contactListener; //Variable declared and #include "ContactListener.h" is present at the top

HelloWorldScene.cpp

_contactListener = new CContactListener(); //This line gets the error
_world->SetContactListener(_contactListener);

ContactListener.h

class CContactListener : public b2ContactListener {
public:

CContactListener();
~CContactListener();
std::vector<ContactData>_contacts;
virtual void BeginContact(b2Contact* contact);
virtual void EndContact(b2Contact* contact);
virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);    
virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);

};

ContactListener.cpp

#include "ContactListener.h"
CContactListener::CContactListener(): _contacts() 
{
}
CContactListener::~CContactListener() 
{
}
//...other functions

CContactListener.cpp未添加到Xcode的目标构建中。我只是在文件检查器中选中了项目的目标框。ccp文件。简单的修复。