Objective-c 面向对象画图形(此程序不符合内存管理规则)
来源:互联网 发布:淘宝收藏店铺怎么设置 编辑:程序博客网 时间:2024/05/18 13:27
在同一个文件中,没有分割出来
#import <Foundation/Foundation.h>// --------------------------------------------------// constants for the different kinds of shapes and their colorstypedef enum {kRedColor,kGreenColor,kBlueColor} ShapeColor;// --------------------------------------------------// Shape bounding rectangle//声明结构用于形状边界//为什么用结构来定义边界,因为结构可以方便的使用//例:ShapeRect rect_0 = {0, 0, 1, 1};typedef struct {int x, y, width, height;} ShapeRect;// --------------------------------------------------// convert from the ShapeColor enum value to a human-readable nameNSString *colorName (ShapeColor color);NSString *colorName (ShapeColor color){switch (color) {case kRedColor:return @"red";break;case kGreenColor:return @"green";break;case kBlueColor:return @"blue";break;}return @"no clue";} // colorName// --------------------------------------------------// All about Circles@interface Circle : NSObject{ ShapeColor fillColor; ShapeRect bounds;}- (void) setFillColor: (ShapeColor) fillColor;- (void) setBounds: (ShapeRect) bounds;- (void) draw;@end // Circle@implementation Circle- (void) setFillColor: (ShapeColor) c{fillColor = c;} // setFillColor- (void) setBounds: (ShapeRect) b{bounds = b;} // setBounds- (void) draw{NSLog (@"drawing a circle at (%d %d %d %d) in %@", bounds.x, bounds.y, bounds.width, bounds.height, colorName(fillColor));} // draw@end // Circle// --------------------------------------------------// All about Rectangles@interface Rectangle : NSObject{ShapeColorfillColor;ShapeRectbounds;}- (void) setFillColor: (ShapeColor) fillColor;- (void) setBounds: (ShapeRect) bounds;- (void) draw;@end // Rectangle@implementation Rectangle- (void) setFillColor: (ShapeColor) c{fillColor = c;} // setFillColor- (void) setBounds: (ShapeRect) b{bounds = b;} // setBounds- (void) draw{NSLog (@"drawing a rectangle at (%d %d %d %d) in %@", bounds.x, bounds.y, bounds.width, bounds.height, colorName(fillColor));} // draw@end // Rectangle// --------------------------------------------------// All about OblateSphereoids@interface OblateSphereoid : NSObject{ShapeColorfillColor;ShapeRectbounds;}- (void) setFillColor: (ShapeColor) fillColor;- (void) setBounds: (ShapeRect) bounds;- (void) draw;@end // OblateSphereoid@implementation OblateSphereoid- (void) setFillColor: (ShapeColor) c{fillColor = c;} // setFillColor- (void) setBounds: (ShapeRect) b{bounds = b;} // setBounds- (void) draw{NSLog (@"drawing an egg at (%d %d %d %d) in %@", bounds.x, bounds.y, bounds.width, bounds.height, colorName(fillColor));} // draw@end // OblateSphereoid// --------------------------------------------------// Draw the shapesvoid drawShapes (id shape, int count);void drawShapes (id shape, int count) // 注意,这里和书上不同,上上为 id shapes[],但在xcode4.2中编译错误,抛Must explicitly describe intended ownership of an object array parameter{[shape draw];} // drawShapes// --------------------------------------------------// The main function. Make the shapes and draw themint main (int argc, const char * argv[]) {id shapes[3];ShapeRect rect0 = { 0, 0, 10, 30 };shapes[0] = [Circle new];[shapes[0] setBounds: rect0];[shapes[0] setFillColor: kRedColor];drawShapes (shapes[0], 3); ShapeRect rect1 = { 30, 40, 50, 60 };shapes[1] = [Rectangle new];[shapes[1] setBounds: rect1];[shapes[1] setFillColor: kGreenColor]; drawShapes (shapes[1], 3);ShapeRect rect2 = { 15, 19, 37, 29 };shapes[2] = [OblateSphereoid new];[shapes[2] setBounds: rect2];[shapes[2] setFillColor: kBlueColor]; drawShapes (shapes[2], 3);return (0);} // main
阅读全文
0 0
- Objective-c 面向对象画图形(此程序不符合内存管理规则)
- obj c car 未拆分(此程序不符合内存管理规则)
- obj c car 各类已拆分(此程序不符合内存管理规则)
- objective-c内存管理规则
- objective C程序 内存管理
- Objective-C 集合对象的内存管理
- Objective-C 【集合对象内存管理】
- Objective-c 内存管理-僵尸对象
- [转载]Objective-C中内存管理的规则
- iOS学习(十)Objective-C 内存管理规则
- Objective C面向对象
- objective-c面向对象
- Objective-C 面向对象
- Objective-c - 单个对象的内存管理(内存泄漏)
- objective-c内存管理
- Objective-c 内存管理
- Objective-C内存管理~~
- Objective-C内存管理
- 关于LNK2005的错误
- 论文素材 Yolo
- 字符编码(三) 字节序、bit序、 有效位
- obj c 画 图形 过程式开发
- 1057. 数零壹(20)
- Objective-c 面向对象画图形(此程序不符合内存管理规则)
- TCP/IP 协议簇学习
- C++11 std::bind std::function 变参函数
- 夜间模式的切换的实现方式
- win7激活工具终极版本
- servlet 总结
- error: Semantic Issue: Interface type cannot be statically allocated
- tomcat 源码学习
- Must explicitly describe intended ownership of an object array parameter