Hi,

I am currently working my way through Learn Objective C on the Mac, and have typed one of the code samples into Xcode (ver 3.2), however Xcode gives me a compile error, I think I have typed the code letter for letter, so I was just wondering if someone could tell me why the following code will not compile?

#import <Foundation/Foundation.h>

typedef enum {
        kCircle,
        kRectange,
        kOblateSpheroid
} ShapeType;

typedef enum {
        kRedColor,
        kGreenColor,
        kBlueColor
} ShapeColor;

typedef struct {
        int x, y, width, height;
} ShapeRect;

typedef struct{
        ShapeType type;
        ShapeColor fillColor;
        ShapeRect bounds;
} Shape;

        
int main (int argc, const char * argv[]) {

    Shape shapes[3];
        ShapeRect rect0 = {0, 0, 10, 30};
        shapes[0].type = kCircle;
        shapes[0].fillColor = kRedColor;
        shapes[0].bounds = rect0;
        
        ShapeRect rect1 = {30, 40, 50, 60};
        shapes[1].type = kRectange;
        shapes[1].fillColor = kGreenColor;
        shapes[1].bounds = rect1;
        
        ShapeRect rect2 = {15, 18, 37, 29};
        shapes[2].type = kOblateSpheroid;
        shapes[2].fillColor = kBlueColor;
        shapes[2].bounds = rect2;
        
        
        drawShapes(shapes, 3);
        
        return(0);
        
}// main

void drawShapes(Shape shapes[], int count){
        int i;
        for(i = 0; i< count; i++){
                switch(shapes[i].type){
                        case kCircle:
                                drawCircle(shapes[i].bounds, 
shapes[i].fillColor);
                                break;
                        case kRectange:
                                drawRectangle(shapes[i].bounds, 
shapes[i].fillColor);
                                break;
                        case kOblateSpheroid:
                                drawEgg(shapes[i].bounds, shapes[i].fillColor);
                                break;
                }
        }
} // drawShapes

void drawCircle (ShapeRect bounds, ShapeColor fillColor){
NSLog(@"drawing a circle at (%d %d %d %d) int %@", bounds.x, bounds.y, bounds.width, bounds.height, colorName(fillColor));
} // drawCircle
void drawRectangle (ShapeRect bounds, ShapeColor fillColor){
NSLog(@"drawing a rectangle at (%d %d %d %d) int %@", bounds.x, bounds.y, bounds.width, bounds.height, colorName(fillColor));
} // drawRectangle
void drawEgg (ShapeRect bounds, ShapeColor fillColor){
NSLog(@"drawing a egg at (%d %d %d %d) int %@", bounds.x, bounds.y, bounds.width, bounds.height, colorName(fillColor));
} // drawEgg

NSString* colorName(ShapeColor colName){
        switch (colName) {
                case kRedColor:
                        return @"red";                
                        break;
                case kGreenColor:
                        return @"green";
                        break;
                case kBlueColor:
                        return @"blue";
                        break;
        }
        return @"No clue";
}// colorName

The error i get is:
"Conflicting types for 'colorName'

Kind Regards
Mick Walker

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to