#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;
}
when i try to run this code This program gives the error "cannot find protocol declaration for logging Why?
当我试图运行这个程序时,这个程序给出的错误是“无法找到日志记录的协议,为什么?”
1 个解决方案
#1
0
Declare your protocol in .h
file like this below in-spite of declaring in .m
file:-
在.h文件中声明您的协议,尽管在.m文件中声明:-。
#import <Foundation/Foundation.h>
@protocol logging
-(void)log;
@end
@interface dog:NSObject<logging>{
@private
int age;
}
@property int age;
@end
#1
0
Declare your protocol in .h
file like this below in-spite of declaring in .m
file:-
在.h文件中声明您的协议,尽管在.m文件中声明:-。
#import <Foundation/Foundation.h>
@protocol logging
-(void)log;
@end
@interface dog:NSObject<logging>{
@private
int age;
}
@property int age;
@end