저는 프로젝트의 아주 작은 부분에 C++을 사용할 것입니다. 내가 뭔가 잘못 코딩해야합니다,하지만 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) {
// ...
}
선언되지 않은? 흠. 나는 header에서 "public :"키워드 바로 뒤에 그것을 선언하고 있다고 생각했다.
내가 여기서 잘못 할 수 있습니까? 감사합니다. J.
그 설명을 위해 어이 감사합니다 :) 완벽한 해결책! n.b. id AbstractContactListener는 실제로 코드 샘플 외부에서 선언되었습니다. 그래도 지적 해 주셔서 고마워. ;-) – Jem