本帖最后由 onlyanswer 于 2015-12-3 16:23 编辑
- #import <Foundation/Foundation.h>
- @interface Phone : NSObject{
- @public
- float screen;
- int cell;
- }
- -(void) call;
- @end
- @implementation Phone
- -(void) call{
- NSLog(@"%f %d电话拨通了",screen,cell);
- }
- @end
- int main(){
- Phone* iphone=[Phone new];
- iphone->screen=8.9f;
- iphone->cell=10000;
- [iphone call];
- Phone* gphone=[Phone new];
- gphone->screen=3.9f;
- gphone->cell=5000;
- [gphone call];
- [iphone call];
- return 0;
- }
复制代码
有一点就是可以在方法中直接使用成员变量打印结果
2015-12-03 16:15:26.474 a.out[989:91995] 8.900000 10000电话拨通了 2015-12-03 16:15:26.475 a.out[989:91995] 3.900000 5000电话拨通了 2015-12-03 16:15:26.475 a.out[989:91995] 8.900000 10000电话拨通了 看打印结果,其实就是使用变量名对应的属性值
|