Reputation: 85955
I have 3 files.
// 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>
This makes compile-time error.
/Users/eonil/Work/Trials/Box2DTest/Library/Box2D/Common/b2Settings.h:22:10: fatal error: 'cassert' file not found [1]
It looks I have to do something special when importing Objective-C++ from Objective-C. But I can't figure out what it is. And I'm not sure even that is possible or not. What's that..?
Upvotes: 1
Views: 1683
Reputation: 40336
Don't include C.h in B.h. Rather say struct C;
. This will allow you to forward declare the type in a way that is compatible with Objective-C. In the mm
include C.h
.
Upvotes: 4