XCode 开发时,一个小BUG,记录之.
2010-06-11 11:57
393 查看
1):Rectangle.h
//
// Created by dhanzhang on 10-6-11.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface Rectangle : NSObject {
int width;
int height;
}
-(Rectangle*) initWithWidth: (int) w height: (int) h;
-(void) setWidth: (int) w;
-(void) setHeight: (int) h;
-(void) setWidth: (int) w height: (int) h;
-(int) width;
-(int) height;
-(void) print;
@end
@interface Square: Rectangle
-(Square*) initWithSize: (int) s;
-(void) setSize: (int) s;
-(int) size;
@end
@implementation Rectangle
-(Rectangle*) initWithWidth: (int) w height: (int) h {
self = [super init];
if ( self ) {
[self setWidth: w height: h];
}
return self;
}
-(void) setWidth: (int) w {
width = w;
}
-(void) setHeight: (int) h {
height = h;
}
-(void) setWidth: (int) w height: (int) h {
width = w;
height = h;
}
-(int) width {
return width;
}
-(int) height {
return height;
}
-(void) print {
printf( "width = %i, height = %i", width, height );
}
@end
//-----------Square
@implementation Square
-(Square*) initWithSize: (int) s {
self = [super init];
if ( self ) {
[self setSize: s];
}
return self;
}
-(void) setSize: (int) s {
width = s;
height = s;
}
-(int) size {
return width;
}
-(void) setWidth: (int) w {
[self setSize: w];
}
-(void) setHeight: (int) h {
[self setSize: h];
}
@end
------------------调用时的一个小问题---------
void RECT()
{
Rectangle *rec = [[Rectangle alloc] initWithWidth: 10 height: 20];
Square *sq = [[Square alloc] initWithSize:13 ];//------------Build 失败.....
//正确的写法如下:
/*-------不知道会不会造成泄露
Square *sq = [[Square alloc] init ];
[sq initWithSize:13];//----调用了2次?
*/
//或者如下
Square *sq = [(Square *)[Square alloc] initWithSize:13 ];
[sq setWidth: 20];
[sq print];
[rec release];
[sq release];
}
//
// Created by dhanzhang on 10-6-11.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface Rectangle : NSObject {
int width;
int height;
}
-(Rectangle*) initWithWidth: (int) w height: (int) h;
-(void) setWidth: (int) w;
-(void) setHeight: (int) h;
-(void) setWidth: (int) w height: (int) h;
-(int) width;
-(int) height;
-(void) print;
@end
@interface Square: Rectangle
-(Square*) initWithSize: (int) s;
-(void) setSize: (int) s;
-(int) size;
@end
@implementation Rectangle
-(Rectangle*) initWithWidth: (int) w height: (int) h {
self = [super init];
if ( self ) {
[self setWidth: w height: h];
}
return self;
}
-(void) setWidth: (int) w {
width = w;
}
-(void) setHeight: (int) h {
height = h;
}
-(void) setWidth: (int) w height: (int) h {
width = w;
height = h;
}
-(int) width {
return width;
}
-(int) height {
return height;
}
-(void) print {
printf( "width = %i, height = %i", width, height );
}
@end
//-----------Square
@implementation Square
-(Square*) initWithSize: (int) s {
self = [super init];
if ( self ) {
[self setSize: s];
}
return self;
}
-(void) setSize: (int) s {
width = s;
height = s;
}
-(int) size {
return width;
}
-(void) setWidth: (int) w {
[self setSize: w];
}
-(void) setHeight: (int) h {
[self setSize: h];
}
@end
------------------调用时的一个小问题---------
void RECT()
{
Rectangle *rec = [[Rectangle alloc] initWithWidth: 10 height: 20];
Square *sq = [[Square alloc] initWithSize:13 ];//------------Build 失败.....
//正确的写法如下:
/*-------不知道会不会造成泄露
Square *sq = [[Square alloc] init ];
[sq initWithSize:13];//----调用了2次?
*/
//或者如下
Square *sq = [(Square *)[Square alloc] initWithSize:13 ];
[sq setWidth: 20];
[sq print];
[rec release];
[sq release];
}
相关文章推荐
- XCode 开发时,一个小BUG,记录之.
- iOS开发Xcode崩溃在main函数入口时如何定位Bug的一个小方法以及一个恶心的bug介绍
- 记录一个关于互联网、网页设计、Web开发、服务器运维优化、项目管理、网站运营、网站安全的网站
- 今早处理了一个小bug,记录一下怕以后忘记
- iOS BUG整理-记录我近期视频开发遇到的问题
- 记录一个safari4 bug
- 【Android开发】找乐,一个笑话App的制作过程记录
- 记录一个cell的Action事件无响应bug
- 数据库开发红皮书实例遇到的一些问题:“找不到可安装的ISAM” “BOF或EOF中有一个是'真',或者当前的记录已被删除……”
- Android开发之一个未解决的bug
- 【深入浅出IOS开发】Xcode 6如何创建一个空的Empty Application
- 寻找bug并消灭系列——记录在Android开发所遇到的bug(二)
- 自己动手开发一个Xcode插件
- IOS开发之Xcode下使用多target, 让同一份代码,一个工程 Project 管理多个app
- 第一次使用csdn的博客,记录一个小产品的开发过程
- 【记录开发中遇到问题】修改xcode安装目录后终端找不到路径方法
- 记录一个前端bug的解决过程
- 一个简单的 .Net Vim 引擎 LibNVim 开发记录 (三)
- 一个难倒 3年 android开发经验 " 工程师 " 的 "bug"
- binbinyang---今天有时间,我要记录昨天的一个小BUG...