2011-03-13 5 views
1

3 개의 파일이 있습니다.[C++] 클래스를 [objective-c] 클래스로 임포트하는 [objective-C++] 클래스를 임포트하는 방법은 무엇입니까?

// A.h/A.m, Objective-C. 
#import "B.h" 
@interface A 
{ 
    B* b; 
} 
@end 
// Uses instance method of B in implementation. 



// B.h/B.mm, Objective-C++. 
#import "C.h" 
@interface B 
{ 
    C c; // c is declared without pointer. 
} 
@end 
// Uses member methods of C in implementation. 



// C.h/C.cpp, C++. 
#include <Box2D/Box2D.h> // C++ library.  
class C 
{ 
    private: 
    b2World  world; 
    b2Body*  ground; 
    b2Body*  ball; 

    public: 

    PhysicsSimulator(); 
    ~PhysicsSimulator(); 

    void setupWorld(); 
    void cleanupWorld(); 

    void tickWorld(); 
}; 
// One file of Box2D library include <cassert> 

이렇게하면 컴파일 타임 오류가 발생합니다.

/Users/eonil/Work/Trials/Box2DTest/Library/Box2D/Common/b2Settings.h:22:10: fatal error: 'cassert' file not found [1] 

Objective-C에서 Objective-C++를 가져올 때 특별한 것을해야합니다. 그러나 나는 그것이 무엇인지 알 수 없다. 그리고 나는 그것이 가능한지 확실치 않습니다. 그게 .. .. 뭐야?

답변

4

B.h에 C.h를 포함하지 마십시오. 오히려 struct C;라고 말하십시오. 이렇게하면 Objective-C와 호환되는 방식으로 형식을 선언 할 수 있습니다. mm에는 C.h이 포함됩니다.

+0

오, 죄송합니다. 중요한 점은 실수입니다. 'B'의'c'는 포인터없이 선언됩니다. 나는 질문을 수정했다. – Eonil

+0

일반 Objective-C에서는이 작업을 수행 할 수 없습니다. C++ 클래스를 Obj-C 클래스의 멤버로 드롭하기 만하면 Objective-C++이되어야합니다. –

+0

감사합니다. :) – Eonil

관련 문제