level 1
baoyixin1997
楼主
现在是El Capitan下的Xcode 7 beta 4,教程书上的一段代码无法编译,我明白它说的错误,但是我没有觉得有这个错误啊……

代码:
#import <Foundation/Foundation.h>
typedef enum {circle,rectangle,egg} shapeType;
typedef enum {red,green,blue} shapeColour;
typedef struct {int x,y,width,height;} shapeRect;
typedef struct {shapeType type; shapeColour colour; shapeRect bounds;} Shape;
int main(int argc, const char *argv[])
{
Shape shapes[3];
shapeRect rect0={0,0,10,30};
shapes[0].type=circle;
shapes[0].colour=red;
shapes[0].bounds=rect0;
shapeRect rect1={30,40,50,60};
shapes[1].type=rectangle;
shapes[1].colour=green;
shapes[1].bounds=rect1;
shapeRect rect2={15,18,37,29};
shapes[2].type=egg;
shapes[2].colour=blue;
shapes[2].bounds=rect2;
drawShapes(shapes,3);
return(0);
}
void drawShapes(Shape shapes[],int count)
{
for (int i=0; i<count; i++) {
switch (shapes[i].type) {
case circle:
drawCircle(shapes[i].bounds,shapes[i].colour);
break;
case rectangle:
drawRectangle(shapes[i].bounds,shapes[i].colour);
break;
case egg:
drawEgg(shapes[i].bounds,shapes[i].colour);
break;
}
}
}
void drawCirle(shapeRect bounds,shapeColour colour)
{
NSLog(@"Drawing a circle at (%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colourName(colour));
}
void drawRectangle(shapeRect bounds,shapeColour colour)
{
NSLog(@"Drawing a rectangle at (%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colourName(colour));
}
void drawEgg(shapeRect bounds,shapeColour colour)
{
NSLog(@"Drawing an egg at (%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colourName(colour));
}
NSString *colourName(shapeColour colourName)
{
switch (colourName) {
case red:
return @"red";
break;
case green:
return @"green";
case blue:
return @"blue";
}
return @"no clue";
}
2015年08月30日 15点08分
1

代码:#import <Foundation/Foundation.h>
typedef enum {circle,rectangle,egg} shapeType;
typedef enum {red,green,blue} shapeColour;
typedef struct {int x,y,width,height;} shapeRect;
typedef struct {shapeType type; shapeColour colour; shapeRect bounds;} Shape;
int main(int argc, const char *argv[])
{
Shape shapes[3];
shapeRect rect0={0,0,10,30};
shapes[0].type=circle;
shapes[0].colour=red;
shapes[0].bounds=rect0;
shapeRect rect1={30,40,50,60};
shapes[1].type=rectangle;
shapes[1].colour=green;
shapes[1].bounds=rect1;
shapeRect rect2={15,18,37,29};
shapes[2].type=egg;
shapes[2].colour=blue;
shapes[2].bounds=rect2;
drawShapes(shapes,3);
return(0);
}
void drawShapes(Shape shapes[],int count)
{
for (int i=0; i<count; i++) {
switch (shapes[i].type) {
case circle:
drawCircle(shapes[i].bounds,shapes[i].colour);
break;
case rectangle:
drawRectangle(shapes[i].bounds,shapes[i].colour);
break;
case egg:
drawEgg(shapes[i].bounds,shapes[i].colour);
break;
}
}
}
void drawCirle(shapeRect bounds,shapeColour colour)
{
NSLog(@"Drawing a circle at (%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colourName(colour));
}
void drawRectangle(shapeRect bounds,shapeColour colour)
{
NSLog(@"Drawing a rectangle at (%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colourName(colour));
}
void drawEgg(shapeRect bounds,shapeColour colour)
{
NSLog(@"Drawing an egg at (%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colourName(colour));
}
NSString *colourName(shapeColour colourName)
{
switch (colourName) {
case red:
return @"red";
break;
case green:
return @"green";
case blue:
return @"blue";
}
return @"no clue";
}