954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Again With a Very Frustrating compilation error…

Hey all… I've been working with Xcode, and an Objective C text book, obviously trying to learn Objective C. When I follow along with the text and type the examples or even when I copy and paste, with out fail there are always several compilation errors. Regardless of how careful I am, or how meticulously I review the code the errors persist. I'm am beginning to think that my computer or the XCode software is the issue but maybe some of you fellow geeks can help me out. The following is an example of what I mean… a Simple program to deal with rectangle Objects. There are three files..
@interface, @Implementation, and the main method.

There are never any compilation errors in this file. Never.

#import <Cocoa/Cocoa.h>


@interface Rectangle : NSObject {
	int width;
	int height;
}

@property int width, height;
-(int) area;
-(int) perimeter;
-(void) setWidth (int) w andHeight: (int) h;

@end


There is a single error message for this implementation section, and oddly enough it is with the #import "Rectangle.h" statement. The error states, "error: syntax error before '(' token" WTF?

There are also two warnings associated with the @end line in this file. The compiler is telling me
1) Incomplete Implementation of class 'Rectangle'
2) Method definition for '-setWidth' notFound

WTF^12 ?????

#import "Rectangle.h"
@implementation Rectangle

@synthesize width, height;

-(void) setWidth: (int) w andHeight: (int) h {
	width = w;
	height = h;
}

-(int) area { return width * height;}
-(int) perimeter { return ((width + height) * 2);}

@end


This main has one error, again with the import statement #import "Rectangle.h". And it also has a warning at the line where i invoke the method [myRect setWidth: 5 andHeight: 8]. It is the line right below where I allocate memory space and initialize myRect as a Rectangle object.

#import <Foundation/Foundation.h>
#import "Rectangle.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	
	Rectangle *myRect = [[Rectangle alloc] init];
	[myRect setWidth: 5 andHeight: 8];
	NSLog (@"Rectangle: w = %i, h = %i", myRect.width, myRect.height);
	NSLog (@"Area = %i, Perimeter = %i", [myRect area], [myRect perimeter]);
	[myRect release];
	
	[pool drain];
    return 0;
}

So that is it. My entire program. Very simple and straight forward, copied word for word from the text book that is supposed to be teaching me how to code in objective c, and not how to make Xcode do wtf it is supposed to do.

I might have missed something really simple and am taking the risk of looking like a fool here, but can any one tell me where the hell is waldo? so to speak… lol.

rue64ja
Light Poster
34 posts since Mar 2010
Reputation Points: 10
Solved Threads: 4
 

-(void) setWidth (int) w andHeight: (int) h;
should be

-(void) setWidth: (int) w andHeight: (int) h;

Very very late but still an answer :)

huntaz556
Newbie Poster
20 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

One colon makes all the difference. Good eye spoting that one huntaz556.

dioioib
Junior Poster in Training
55 posts since Feb 2011
Reputation Points: 14
Solved Threads: 2
 

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: