直接上代码
[code]
include <iostream>
include <stdlib.h>
using namespace std;
class Base { public: virtual void virtualFunc() { cout << "BaseVirtualFunc" << endl; } void func() { cout << "BaseFunc" << endl; } void call() { virtualFunc(); func(); } };
class Derive : public Base { public: void virtualFunc() { cout << "SubClassVirtualFunc" << endl; } void func() { cout << "SubClassFunc" << endl; } };
int main(int argc, char argv[]) { Derive d; d.call(); /-------------------------output-------------------------/ /SubClassVirtualFunc / /BaseFunc / /--------------------------------------------------------*/ system("PAUSE"); }
[/code]