• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Unable to Compile Simple Application (Errors)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unable to Compile Simple Application (Errors)


  • Subject: Unable to Compile Simple Application (Errors)
  • From: Mick Walker <email@hidden>
  • Date: Sat, 26 Sep 2009 20:41:57 +0100

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Unable to Compile Simple Application (Errors)
      • From: Kyle Sluder <email@hidden>
    • Re: Unable to Compile Simple Application (Errors)
      • From: Graham Cox <email@hidden>
  • Prev by Date: NSBitmapImageRep caching behavior in Snow Leopard
  • Next by Date: Re: Creating a radar sweep effect
  • Previous by thread: Re: NSBitmapImageRep caching behavior in Snow Leopard
  • Next by thread: Re: Unable to Compile Simple Application (Errors)
  • Index(es):
    • Date
    • Thread