//#C++语言 对动物的行为实现多态
http://www.pythonschool.com/python/99.html #include <iostream> using namespace std; class CAnimal { public: virtual void Cry()=0;//纯虚函数 }; class CDog:public CAnimal { public: virtual void Cry() { cout << "wang wang! The dog sound!\n" << endl; } }; class CCat:public CAnimal { public: virtual void Cry() { cout << "miao miao! The cat sound!\n" << endl; } }; int main(int argc, char* argv[]) { /* CAnimal *p; CDog cdog; p = &cdog; p->Cry(); CCat ccat; p = &ccat; p->Cry(); */ CAnimal *animal; animal = new CDog; animal->Cry(); delete animal; animal = new CCat; animal->Cry(); delete animal; return 0; }