Problem with using classes

Discussion in 'iOS Programming' started by D.A.N., Mar 2, 2009.

  1. macrumors newbie

    Joined:
    Mar 2, 2009
    #1
    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;
    }


    @end

    and this is level.


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

    @implementation Level

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

    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?
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You need to put the following line in a method within the Level class:
    Code:
    Object *myObj = [[Object alloc] init];
    Or you can define it as static, like so:
    Code:
    static Object *myObj = [[Object alloc] init];
     

Share This Page