下面的代码是正确的,但是定义类,在interface中定义成员变量和在implementation中定义成员变量有什么区别?
#import <Foundation/Foundation.h>
@interface Person1 : NSObject
{
@public
NSString *name;
}
@end
@implementation Person1
@end
@interface Person2: NSObject
@end
@implementation Person2
{
@public
NSString *name;
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person1 *p1 = [[Person1 alloc]init];
Person2 *p2 = [[Person2 alloc]init];
p1->name = @"小明";
p2->name = @"小红";
NSLog(@"%@",p1->name);
NSLog(@"%@",p2->name);
}
return 0;
}
|
|