home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / OOPWLD.ZIP / POLY / CRISPIES.CPP next >
Encoding:
C/C++ Source or Header  |  1990-07-26  |  548 b   |  20 lines

  1. // CRISPIES.CPP : virtual functions made simple
  2. #include <stdio.h>
  3. struct rice {    // Base class
  4.   virtual void talk() {}  // common interface to all types of rice
  5. };
  6. struct snap : rice {
  7.   void talk() { puts("SNAP!"); }  // different implementations for each type
  8. };
  9. struct crackle : rice {
  10.   void talk() { puts("CRACKLE!"); }
  11. };
  12. struct pop : rice {
  13.   void talk() { puts("POP!"); }
  14. };
  15.  
  16. main() {
  17.   rice * bowl[] = { new snap, new crackle, new pop };
  18.   for(int i = 0; i < sizeof(bowl)/sizeof(bowl[0]); i++)
  19.     bowl[i]->talk();
  20. }