Objective-C on GNUstep AutoReleasePool 未声明的问题
我是 Objective-C 的新手,在 GNUstep 和 MinGW 环境中工作。我正在编译此代码,但出现错误:
#import "Foundation/Foundation.h"
@interface C : NSObject
{
float f;
}
- (void) gamerHell: (NSString *) name : (NSString *) lastName ;
@end
@implementation C
- (void) gamerHell: (NSString *) firstName : (NSString *) lastName {
NSLog(@"Welcome, %s %s",firstName,lastName);
}
@end
int main(int argc , const char * argv[]){
NSAutoReleasePool * pool = [[NSAutoReleasePool alloc] init];
C *ob = [[C alloc] init];
[ob gamerHell: @"SHAN" : @"UL HAQ"];
[ob release];
[pool drain];
return 0;
}
它给出如下编译时错误:
“NSAutoReleasePool”未声明(在此函数中首次使用)
我应该怎么做才能克服此错误?
I'm new to Objective-C and working in GNUstep and MinGW environment. I am compiling this code but having an error:
#import "Foundation/Foundation.h"
@interface C : NSObject
{
float f;
}
- (void) gamerHell: (NSString *) name : (NSString *) lastName ;
@end
@implementation C
- (void) gamerHell: (NSString *) firstName : (NSString *) lastName {
NSLog(@"Welcome, %s %s",firstName,lastName);
}
@end
int main(int argc , const char * argv[]){
NSAutoReleasePool * pool = [[NSAutoReleasePool alloc] init];
C *ob = [[C alloc] init];
[ob gamerHell: @"SHAN" : @"UL HAQ"];
[ob release];
[pool drain];
return 0;
}
It is giving a compile-time error like this:
'NSAutoReleasePool' is undeclared (first use in this function)
What should I do to overcome this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
NSAutoreleasePool
而不是NSAutoReleasePool
(使用小写的r
)。Try using
NSAutoreleasePool
instead ofNSAutoReleasePool
(with a lowercaser
).亚当解决了您报告的问题,您的类名有一个拼写错误。但是,您还会遇到一些其他问题,我认为了解这些问题会有所帮助。
- (void) hellowWithFirstName:(NSString*)firstName lastName:(NSString*)lastName;
我知道您是 Objective-C 的新手,这些都是刚学习这门语言的人常见的烦恼。因此,请将这些观点视为友好的建议,而不是严厉的批评。
Adam nailed the problem you reported, you have a typo in the class name. However, there are a few other problems you'll run into that I figure it would help to know about.
- (void) hellowWithFirstName:(NSString*)firstName lastName:(NSString*)lastName;
I understand you're new to Objective-C, and these are all common afflictions for people just learning the language. Accordingly, please take these points as friendly advice, not harsh criticism.
从切换
到删除空格。
在 * 为我处理错误消息后,
switch from
to
removing the space after the * took care of the error message for me.