当我尝试从 SpeakHere 集成录制/播放代码时,我的编译器报告了很多错误。我遵循了使用 .mm 文件来包含 cpp 包含文件的建议,唯一的例外是我使用启用了 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 文件。我知道我会在某个地方遗漏一些东西,任何人都可以指出吗?
提前致谢,
肖恩