c++ - 有没有人成功为 ARC 移植 SpeakHere?

标签 c++ ios ios5 compilation xcode4.2

当我尝试集成来自 SpeakHere 的录音/播放代码时,我的编译器报告了很多错误。 我遵循了使用 .mm 文件来包含 cpp 包含文件的建议,唯一的异常(exception)是我使用的是启用了 ARC 的 iOS 5。

我的代码是:

//header file
#import "AQPlayer.h"
#import "AQRecorder.h"

@interface MyClass : NSObject {

UIButton *record;
UIButton *cancel;
UIButton *stop;
UIButton *play;

//
AQPlayer*                   player;
AQRecorder*                 recorder;
BOOL                        playbackWasInterrupted;
BOOL                        playbackWasPaused;

CFStringRef                 recordFilePath; 
}

@property (nonatomic, retain) IBOutlet DrawerAudioNote *dnote;
@property (nonatomic, retain) IBOutlet UIButton *record;
@property (nonatomic, retain) IBOutlet UIButton *cancel;
@property (nonatomic, retain) IBOutlet UIButton *stop;
@property (nonatomic, retain) IBOutlet UIButton *play;

- (IBAction) doRecord:(id)sender;
- (IBAction) doStop:(id)sender;
- (IBAction) doCancel:(id)sender;
- (IBAction) doPlay:(id)sender;

//
@property (readonly)            AQPlayer            *player;
@property (readonly)            AQRecorder          *recorder;

//.mm file (no compile error)
@import "MyClass.h"
@implementation MyClass

@synthesize record, cancel, stop, play;
@synthesize playbackWasInterrupted;
@synthesize player, recorder;

//CAXException.h (an example cpp file with compile errors)
......
class CAX4CCString { 
//ERROR: Expect ';' after top level declarator
//ERROR: Unknown type name; do you mean 'Class'?
public:
    CAX4CCString(OSStatus error) {
        // see if it appears to be a 4-char-code
        char *str = mStr;
        *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
        if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {         
            str[0] = str[5] = '\'';
            str[6] = '\0';
        } else if (error > -200000 && error < 200000)
            // no, format it as an integer
            sprintf(str, "%d", (int)error);
        else
            sprintf(str, "0x%x", (int)error);
    }
    const char *get() const { return mStr; }
    operator const char *() const { return mStr; }
private:
    char mStr[16];
};

由于“CAX4CCString”类中的编译错误,编译器似乎不理解他正在处理 CPP 文件。 我知道我会在某个地方漏掉一些东西,有人可以指出吗?

提前致谢

肖恩

最佳答案

为什么不对特定文件禁用 ARC?除了有问题的文件外,您的项目仍保留在 ARC 中。将 -fno-objc-arc 添加到您不希望使用 ARC 的文件的编译器标志中。在 Xcode 中,您可以在目标 -> 构建阶段 -> 编译源代码下执行此操作。

关于c++ - 有没有人成功为 ARC 移植 SpeakHere?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7336300/

相关文章:

c++ - 如何在linux可执行文件中使用静态库

iOS 移动设备拉伸(stretch)背景图片

ios - 应用未运行时 UILocalNotification 会触发吗?

iphone - 在 iOS 应用程序中获取全局 IP 地址和国家/地区是否合法?

ios5: drawRect 在 CATiledLayer 中为同一个 Rect 调用了两次

python - C++到Python的算法(径向对称变换)

c++ - 以编程方式为任务计划程序创建/删除任务

c++ - 这个简单的代码会导致内存泄漏吗?

ios - Toast 的 showMessage 函数未出现在 XLPagerTabStrip 中

javascript - iOS 获取过去的登录表单。