摘要: 一.简介 虚函数是C++中用于实现多态(polymorphism)的机制。核心理念就是通过基类访问派生类定义的函数。假设我们有下面的类层次:class A { public: virtual void foo() { cout << "A::foo() is called" << endl; }};class B: public A { public: virtual void foo() { cout << "B::foo() is called" << endl; } }; 那么,在使用的时候,我们可以 阅读全文
posted @ 2011-07-13 23:37 realyan 阅读(653) 评论(0) 推荐(1) 编辑