标签:com class blog http code div img java style javascript color
#include <iostream.h> class base { public: virtual void v() const = 0; virtual void f() const = 0 { // 纯虚函数也有实现内容,但子类仍然必须实现这个虚函数 cout << "base::f()\n"; } }; void base::v() const { cout << "base::v()\n";} // 实现函数写在类的外部 class d : public base { public: // Use the common base code: void v() const { base::v(); } // 纯虚函数也可被子类调用 void f() const { base::f(); } }; main() { d D; D.v(); D.f(); }
输出结果:
base::v()
base::f()
纯虚函数也可以有内容,并被子类调用,布布扣,bubuko.com
标签:com class blog http code div img java style javascript color
原文地址:http://www.cnblogs.com/findumars/p/3695218.html