class animal { public: virtual void enjoy() { cout << "叫聲。。。" << endl; } }; class dog:public animal { public: void enjoy() { cout << "狗叫聲。。。" << endl; } }; class lady { public: animal *a; lady(animal *oo) :a(oo){} void jiao() { a->enjoy(); } }; //測試代碼 animal *g=new dog(); lady ll(g); ll.jiao();//輸出“狗叫聲。。。”