C++虚函数的使用
#include <iostream> using namespace std; class people { public: void Sing() { song(); } private: virtual void song()=0; }; class white : public people { public: void song() { cout << "White Sing" << endl; } }; class black : public people { public: void song() { cout << "Black Sing" << endl; }; }; void main() { people *p = new white(); p->Sing();//输出White Sing p = new black(); p->Sing(); //输出Black Sing int wait; cin >> wait; }