//Date: Sat, 12 Oct 1996 12:54:40 -0700 //From: Paul Tonning //Reply-To: paul@csci.csusb.edu //Organization: California State University San Bernardino //http://web.csusb.edu/public/staff/paul/cs330/class_examples/rice.cc #include /* This is the bowl of rice crispies example given in class(CS330) You may notice that it is different than the implementation given in class. What I had put on the board probably won't work, but this example has been successfully compiled and it does run. paul */ class Rice { public: Rice(){}; Rice(const Rice&){}; virtual void talk(){cout << "Rice Crispies!\n";}; }; class Snap : public Rice { public: void talk(){cout << "Snap\n";}; }; class Crackle : public Rice { public: void talk(){cout <<"Crackle\n";}; }; class Pop : public Rice { public: void talk(){cout <<"Pop\n";}; }; void main(){ Rice base; Rice *bowl[3]= {new Snap,new Crackle,new Pop}; for (int i=0;i<3;i++) bowl[i]->talk(); base.talk(); }