2013-11-24 73 views
1

我在寫同一個.m文件中的Objective-CC函數,現在我想從我的Objective-C類的C部分創建實例。我可以訪問一些NSString, NSData和其他Objective-C類,但我不能訪問我的CustomObjC類。 我試圖#include "CustomObjC.h" ,但我仍然無法創建該類的實例,像這樣:無法在C函數中創建Objective-C類的實例

void _ActivateSpeechDetection(void* self){ 
     CustomObjC *object; 
    } 

和錯誤是:「使用未聲明的標識符CustomObjC的」

任何想法,將金德利感激!

這是.mm文件的樣子:

#import "BonjourClientImpl.h" 

@implementation NetServiceBrowserDelegate 

@synthesize pocketsphinxController; 
@synthesize openEarsEventsObserver; 

- (id)init 
{ 
self = [super init]; 

return self; 
} 


void SetNotificationListeners(){ 

} 

-(void)fireSpeechRecognition{ 

} 

@end 


#import "CustomObjC.h" 

static CustomObjC* obj = nil; //Problem here 

void _fireSpeech(){ 

} 
+0

OK首先使用'#import'而不是'#include'在'.M '文件,其次不是「創建實例」,它是「聲明變量」。 – trojanfoe

+0

這應該沒有問題。你可以在同一個文件中的Objective-C *方法中聲明一個CustomObjC變量嗎? –

+0

顯示'CustomObjC.h'文件的內容。 – trojanfoe

回答

0

嘗試#進口或@class yourClassName

+0

'#import'和'#include'有什麼區別? – trojanfoe

+0

不工作夥伴 –

+0

#import會包含你的文件一次......所以遞歸包含可以忽略......並且如果你使用#include並且你已經包含了那個文件,儘管它將包含在你的類中。 – vivek