View Full Version : Problem with using classes

Mar 2, 2009, 01:56 PM
My problem here is that I have created 2 classes. One called Object, of which there will be multiple instances created, holding coords, and a few other bits of information about the object, and another called level. This one will be used to create and manage these instances.

#import "Object.h"

@implementation Object

-(void) Create {

coordx = 0;
coordy = 0;
active = 0;
turndirection = 0;


and this is level.

#import "Level.h"
#import "Object.h"

@implementation Level

Object *myObj = [[Object alloc] init];

Pretty basic at the moment but I've just started out. My problem is just after creating the new instance of Object I get an error saying "Initializer element is not constant".

What am I doing wrong here?

Mar 2, 2009, 02:59 PM
What am I doing wrong here?
You need to put the following line in a method within the Level class:
Object *myObj = [[Object alloc] init];

Or you can define it as static, like so:
static Object *myObj = [[Object alloc] init];