views:

2337

answers:

2

Im getting these weird errors, but I dont understand them. Here are the errors:

error: variable - sized object may not be initialized (#1)

error: statically allocated instance of Objective-C class 'Joke' (#1)

error: statically allocated instance of Objective-C class 'Joke' (#1)

error: cannot convert to a pointer type (# 2)

(Note: The number after the error will indicate where the error was in my implementation file)

Here is my .m file:

#import "Joke.h"


@implementation Joke
@synthesize joke;
@synthesize rating;


- (id)init {
[super init];
return self;
}

- (void)dealloc {
[joke release];
[super dealloc]; 
}

+ (id)jokeWithValue:(NSString *)joke {
Joke j = [[Joke alloc] init]; // (# 1) This is where #1 errors occurred
j.joke = joke;
return [j autorelease]; // (# 2) This is where #2 errors occurred
 }

@synthesize joke;
@synthesize rating;

@end

Thanks!

+6  A: 

You need a "*" before your variables -- for instance, "Joke *j = [[Joke alloc] init];"

You also only want @synthesize in there once for each property.

xtophyr
Ahhh Thanks! So weird how one little astrid can cause your app to fail!
Daniel Kindler
not really weird. See Jason's answer.
Roger Nolan
+9  A: 

Instances of Objective-C objects must be pointers, which is causing your problem. Your initialization of joke should be:

Joke *j = [[Joke alloc] init];

Also, it's a bad idea for an object to hold onto itself as a circular reference. You would have infinite recursion with j->joke->joke->joke->joke->joke...

Jason Coco