Objective C和c ++导入问题。很简单,但我不明白

时间:2011-02-21 17:56:31

标签: iphone c++ class objective-c++ box2d

我正在使用cocos2d和box2d。(iPhone SDK)如果我要导入box2d,我将其添加到文件 #import“Box2D.h”的顶部,然后我重命名我的班级到“ .mm ”。现在我只有一个类没有一个“.m”文件只是一个“.h”文件。

它看起来像那样,如果我导入box2d它会给我很多错误,因为box2d是c ++,通常我需要将它改为“.mm”但我不能。

#import "Box2D.h"

// Defines individual types of messages that can be sent over the network. One type per packet.
typedef enum
{
    kPacketTypeTime = 1,
    kPacketTypePosition = 2,
    kPacketTypeStartSignal = 3,
} EPacketTypes;

// Note: EPacketType type; must always be the first entry of every Packet struct
// The receiver will first assume the received data to be of type SBasePacket, so it can identify the actual packet by type.
typedef struct
{
    EPacketTypes type;
} SBasePacket;

// the packet for transmitting a score variable
typedef struct
{
    EPacketTypes type;

    float time;
} STimePacket;

// packet to transmit a position
typedef struct
{
    EPacketTypes type;

    b2Vec2 position; //*******************************important**
    float rotation;

} SPositionPacket;

// packet to transmit a start signal
typedef struct
{
    EPacketTypes type;

    BOOL startGame;

} SStartSignalPacket;

为什么我要这样做?在我的代码中查看“ * * important”。我想用b2Vec2。

非常感谢您的阅读。 祝你有愉快的一天:)

1 个答案:

答案 0 :(得分:2)

尝试将标题重命名为.hh,因为编译器仍然将其视为Objective C