我需要在我的项目中使用C++编程,但只是很小的一部分。我可能在编码方面出了问题,但我的C++知识有限,无法解决这个问题...
请查看下面的AbstractContactListener.h和.mm文件。问题出现在isFixtureCollidingWithFixtureOfType(...)方法中,我无法访问_contact向量。我在这里做错了什么?
头文件:
struct JRContact {
b2Fixture *fixtureA;
b2Fixture *fixtureB;
bool operator==(const JRContact& other) const
{
return (fixtureA == other.fixtureA) && (fixtureB == other.fixtureB);
}
};
class AbstractContactListener : public b2ContactListener {
id contactHandler;
public:
std::vector<JRContact>_contacts;
AbstractContactListener(id handler);
~AbstractContactListener();
void isFixtureCollidingWithFixtureOfType(b2Fixture fix, int type);
virtual void BeginContact(b2Contact* contact);
virtual void EndContact(b2Contact* contact);
};
实现:
AbstractContactListener::AbstractContactListener(id handler) : _contacts() {
contactHandler = handler;
}
AbstractContactListener::~AbstractContactListener() {
}
void isFixtureCollidingWithFixtureOfType(b2Fixture fix, int type){
std::vector<JRContact>::iterator ct;
// Next line is faulty... can't call _contacts.begin()
// xCode says: "Use of undeclared identifier _contacts"
ct = _contacts.begin();
}
void AbstractContactListener::BeginContact(b2Contact* contact) {
// ...
}
void AbstractContactListener::EndContact(b2Contact* contact) {
// ...
}
未声明?嗯,我认为我已经在头文件中声明了,就在“public:”关键字后面。
我可能做错了什么?非常感谢! J.