一段代码
- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- @public
- int age;
- double weight;
- }
- - (void)walk;
- - (void)eat;
- @end
- @implementation Person
- - (void)walk
- {
- NSLog(@"%d %d", age, weight);
- }
- - (void)eat
- {
- NSLog(@"%d %d", age, weight);
- }
- @end
- int main()
- {
- Person *p = [Person new];
- p->age = 20;
- p->weight = 40;
-
- Person *p2 = p; // 关注这一段
- p2->age = 30;
- [p walk];
- return 0 ;
- }
复制代码
老师的视频讲解中说p2的值跟p的值相等,个人觉得不是相等啊,p2中存储的应该是p的地址啊,而p中存储的是对象的地址啊,
|
|