_Advanced Object-Oriented Features for C/C++_
by Blake McBride


Example 1: 

defclass  Person  {  /* Define class */
    char    name[30];  /* Private instance variables */
    int     age;
class:
    int     numberOfPeople; /* Private class variables */
};
imeth   SetName(char *nm) { /* Define method */
    strcpy(name, nm);
    return self;
}
imeth   char *GetName() {
    return name;
}
cmeth   int GetNumberOfPeople() {
    return numberOfPeople;
}


Example 2: 

void    myfun() {
   object  obj;
   char   *str;
   obj = New(Person);
   SetName(obj, "Blake");
   str = GetName(obj);
}


Example 3: 

typedef  struct  {
    char    name[30];
    int     age;
} Person;
void    *NewPerson() {
    return malloc(sizeof(Person));
}
void    SetName(void *p, char *nm) {
    strcpy(((Person *)p)->name, nm);
}
char    *GetName(void *p) {
    return ((Person *)p)->name;
}


Example 4: 

void    fun() {
    void    *p;
    char    *str;
    p = NewPerson();
    SetName(p, "Blake");
    str = GetName(p);
}


Example 5: 

int SetName(object obj, char *a)
{
    int (*meth)();
    meth = find_method(ClassOf(obj), SetName_object);
    return meth(obj,a);
}


