2011-09-07 25 views
3

當我試圖整合來自SpeakHere的記錄/播放代碼時,我的編譯器報告了很多錯誤。 我遵循了使用.mm文件來包含cpp包含文件的建議,唯一的例外是我在啓用ARC的情況下使用iOS 5。有沒有人成功將端口SpeakHere用於ARC?

我的代碼是:

//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文件編譯錯誤。 我知道我會在某個地方錯過任何東西,任何人都可以指出?

由於提前,

肖恩

+1

即使有人已經移植SpeakHere到iOS 5與ARC啓用,他們由於合同原因目前不能這樣說。當這些工具超出NDA時,可能值得再次提問。 – Tommy

回答

2

爲什麼不爲特定文件禁用ARC?除了有問題的文件外,您的項目仍在ARC中。將-fno-objc-arc添加到您不想使用ARC的文件的編譯器標誌。在Xcode中,您可以在您的目標 - > Build Phases - > Compile Sources下執行此操作。

0

您在聲明C++類

class CAX4CCString { 

的Objective-C類MyClass內。我擔心這不被Objective-C支持。

我想你可以這樣在全球範圍內宣佈CAX4CCString然後實例,並從你的Objective-C類使用它:

//.mm file 

class CAX4CCString { 
    .... 
}; 


@implementation MyClass 

@synthesize record, cancel, stop, play; 
@synthesize playbackWasInterrupted; 
@synthesize player, recorder; 
... 
    <do something with CAX4CCString> 
@end 
相關問題