First of all, to clear up alot of confusion, don't read too much into the name. A class is a simple way of holding a collection of values in an easily dealt with form.
classes are the only type which can be created; one defines a class as follows:
class myclass { type1 member1; type2 member2, ...; ... }
where type1, type2, etc are type names, and 'myclass' is what you want to refer to the class as. 'class myclass' then becomes a type, which is legal wherever any other type is. (Note: The point of definition is the name, so classes may actually contain instances of themselves).
Class definitions are copied by inheritance, and so should be defined in base objects. They can be defined in .h files, but this will likely get you into trouble.
To create a variable of a class type, simply declare it as you would any other variable:
class myclass myvar;
Note: Like all other LPC variables, the value is initially zero. Classes share the implicit pointer semantics of arrays and mappings, and are freed automatically when nothing points to them any more. A new class instance ins created with the syntax new(class myclass). For example, if myvar had been defined as above, one could initialize it:
myvar = new(class myclass);
and as usual, the initialization could have been included as part of the definition. Members of the class are accessed with the -> operator. One can use a member of a class anywhere one could use a normal variable. For example, the syntax:
myvar->member1 = 1;
Initializes the member 'member1' of myvar to 1.
Here is a quick example:
class event { int when; string what; }class event *history = ({ }); // declare an array of classes
void add(string what) { class this_event = new(class event); // create a new class this_event->when = time(); this_event->what = what; history += ({ this_event }); }
class event get(int idx) { return history[idx]; }
Beek @ZorkMUD, Lima Bean, IdeaExchange, TMI-2, and elsewhere