// PETS.CPP : Conversations with your animals

#include <stdio.h>

struct pet {
   virtual void speak() {}  // function definition
};

struct dog : pet {
   void speak() { puts("Bark!"); }
};

struct cat : pet {
   void speak() { puts("Meow!"); }
};

struct bird : pet {
   void speak() { puts("Tweet!"); }
};

struct goldfish : pet {
   void speak() { puts("!"); }
};

                // aggregate initialization of menagerie
pet* menagerie[] = { new dog, new cat, new bird };
const int sz = sizeof(menagerie)/sizeof(menagerie[0]);

void main(void)
{
   for (int i = 0; i < sz; i++)
      menagerie[i]->speak();
}
