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;
}

当我尝试运行此代码时,此程序给出错误“找不到用于记录的协议声明,为什么?

4

1 回答 1

0

.h尽管在文件中声明,但在下面的文件中声明您的协议.m:-

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

@end
于 2013-10-28T08:21:57.247 回答