2013-10-28 91 views
0
#import <Foundation/Foundation.h> 
@interface dog:NSObject<logging>{ 
@private 
int age; 
} 
@property int age; 

@end 
@implementation dog 
@synthesize age; 
-(void)log{ 
NSLog(@" this is a god having age %d ",age); 
} 
@end 
@protocol logging 
-(void)log; 
@end 
int main(int argc, const char * argv[]) 
{ 
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
dog *loop=[[dog alloc] init]; 
//[dog setAge:6]; 
[dog log]; 
[pool drain]; 
return 0; 
} 

當我嘗試運行這段代碼 這套程序錯誤「無法找到協議聲明登錄 爲什麼?找不到協議聲明的目標C

+0

有一件事我無法找到是壓痕 – 2013-10-28 08:19:58

+0

什麼呢凹陷具有客觀C++做的,否則使代碼易於閱讀,它的一個小代碼。先生,您可以閱讀嗎? – user2889070

+1

@userXXX不,由於缺少縮進(以及一般的空白...),所以**非常難以閱讀**。務必正確縮進代碼。即使它只有3行。 Youknowyoucanreadtextthatlookslikethis,butit'sextremelydifficultsincethere'snoseparationbetweenwords。同樣的事情適用於代碼。 – 2013-10-28 08:27:26

回答

0

中聲明你的協議.h文件中像下面這樣在.m文件中聲明的-spite: -

#import <Foundation/Foundation.h> 
@protocol logging 
-(void)log; 
@end 
@interface dog:NSObject<logging>{ 
@private 
int age; 
} 
@property int age; 

@end