For a client program of the Dog, BigDog, and LittleDog classes to access public methods for these classes, the client program must include the public class Header (H) files for the respective classes. In the following sample code, the client of these classes includes DOG.H, LDOG.H, and BDOG.H files.

/*
 *  DogsMain.C - A client C program to manipulate Dog, LittleDog,
 *               and BigDog objects
 */

#define INCL_NOPMAPI        /* Makes compilation go faster */
                            /* for non-PM programs         */
#define INCL_DOSERRORS
#define INCL_DOS

#include <os2.h>
/* Include declarations for the Dog class       */
#include "dog.h"
/* Include declarations for the LittleDog class */
#include "ldog.h"
/* Include declarations for the BigDog class    */
#include "bdog.h"

int main(VOID)
{
  Dog        *Pokey;   /* Define a Dog       */
  LittleDog  *Zack;    /* Define a LittleDog */
  BigDog     *Pepper;  /* Define a BigDog    */

  /* Instantiate some objects */
  Pokey  = DogNew();
  Zack   = LittleDogNew();
  Pepper = BigDogNew();

  /* Set their breeds */
   __set_breed(Pokey, "Basset Hound");
   __set_breed(Zack, "Yorkshire Terrier");
   __set_breed(Pepper, "Rottweiler");

  /* Display the dog's characteristics */
   _display(Pokey);
   _display(Zack);
   _display(Pepper);

  /* Free the dogs  */
   _somFree(Pokey);
   _somFree(Zack);
   _somFree(Pepper);

   return NO_ERROR;
}

The next figure shows the output from this client program.

My breed is Basset Hound
I say
Unknown Dog Noise

My breed is Yorkshire Terrier
I say
yap yap
yap yap

My breed is Rottweiler
I say
WOOF WOOF
WOOF WOOF
WOOF WOOF
WOOF WOOF


[Back] [Next]