黑马程序员技术交流社区
标题:
急!我不清楚我这怎么回事,没用第三方框架啊!
[打印本页]
作者:
Moebius
时间:
2014-7-19 22:37
标题:
急!我不清楚我这怎么回事,没用第三方框架啊!
本帖最后由 Moebius 于 2014-7-19 23:57 编辑
#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc, const char * argv[])
{
Student *p1 = [[Student alloc] initWithName:@"Jim" andAge:18 andScore:78];
// Student *p2 = [[Student alloc] initWithName:@"Jack" andAge:19 andScore:82];
//
// Student *p3 = [[Student alloc] initWithName:@"May" andAge:17 andScore:99];
//
// Student *p4 = [[Student alloc] initWithName:@"Lily" andAge:18 andScore:60];
//
// Student *p5 = [[Student alloc] initWithName:@"Candy" andAge:18 andScore:75];
NSLog(@"%@",p1);
// [p1 release];
// [p2 release];
// [p3 release];
// [p4 release];
// [p5 release];
return 0;
}
#import <Foundation/Foundation.h>
@interface Student : NSObject
{
int _age;
int _score;
NSString *_name;
}
//年龄 分数 姓名的get set
-(void)setAge:(int)age;
-(int)age;
-(void)setScore:(int)score;
-(int)score;
-(void)setName:(NSString *)name;
-(NSString *)name;
//快速构造器的声明
-(id)initWithName:(NSString *)name andAge:(int)age andScore:(int)score;
@end
#import "Student.h"
@implementation Student
//年龄 分数 姓名的set get的实现
-(void)setAge:(int)age
{
_age = age;
}
-(int)age
{
return _age;
}
-(void)setScore:(int)score
{
_score = score;
}
-(int)score
{
return _score;
}
-(void)setName:(NSString *)name
{
if ( name != _name)
{
[_name release];
_name = [name retain];
}
}
-(NSString *)name
{
return _name;
}
//输出整个学生信息
- (NSString *)description
{
return [NSString stringWithFormat:@"My Name Is %@,Age Is %d.Score Is %d.",_name,_age,_score];
}
//快速构造器的实现
-(id)initWithName:(NSString *)name andAge:(int)age andScore:(int)score
{
if ( self = [super init])
{
_name = name;
_age = age;
_score = score;
}
return self;
}
@end
复制代码
ndefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Student", referenced from:
objc-class-ref in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
网上说是用第三方框架什么的,但是我什么都没用啊,这个怎么回事?
作者:
温天恩
时间:
2014-7-19 23:21
为嘛你的成员变量也要relsase?
作者:
Moebius
时间:
2014-7-19 23:54
温天恩 发表于 2014-7-19 23:21
为嘛你的成员变量也要relsase?
name是字符串,在OC里是对象。所以要release
作者:
Moebius
时间:
2014-7-19 23:57
为什么我换个文件,同样的代码又可以了?这是为什么?
作者:
温天恩
时间:
2014-7-20 14:50
Moebius 发表于 2014-7-19 23:54
name是字符串,在OC里是对象。所以要release
假如你初始化NSString时候没有用alloc,就不用release。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2