PDA

View Full Version : Error: Syntax Error before '-' token.




lase
Aug 11, 2009, 11:55 PM
I'm at wits ends trying to fix this. I've been googling for the last hour about this.

Any ideas?

The error is up in the @interface for Car...

#import <Foundation/Foundation.h>

//classes

@interface Car : NSObject
{
-(NSString *) carModel;
-(NSString *) ownerName;
-int gasAmount;
}

-(void) setModel: (NSString *) m;
-(void) setOwner: (NSString *) o;
-(void) setGas: (int) g;

@end

@implementation Car
{
-(void) setModel: (NSString *) m
{
carModel = m;
}
-(void) setOwner: (NSString *) o
{
ownerName = o;
}
-(void) setGas: g
{
gasAmount = g;
}
@end




int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

Car *myCar = [[Car alloc] init];

[myCar setModel:@"Ford F150"];
[myCar setOwner:@"Anthony Crognale"];
[myCar setGas: 1];

NSLog([myCar carModel]);
NSLog([myCar ownerName]);
NSLog([myCar gasAmount]);

// insert code here...
[pool drain];
return 0;
}



HiRez
Aug 12, 2009, 12:18 AM
Don't put dashes or paretheses with your variable declarations. It should be like this:

@interface Car : NSObject {
NSString *carModel;
NSString *ownerName;
int gasAmount;
}


The method declarations are fine.

HiRez
Aug 12, 2009, 12:35 AM
Hmm, your method implementations need some work though. You need to write "(int) g" for setGas and in the other two where you are assigning objects you need to do some checks and retain/release if you're not using garbage collection. Also have a lot at the documentation for the @synthesize and @property keywords.