class shape{public: shape(){}; virtual void draw() //注意这里设置为虚函数 { 画图形; }};class rectangle :
public shape{public: rectangle(){}; void draw() { 画方形; }};class round :
public shape{public: round(){}; void draw() { 画圆形; }};void main(){ shape
* s; s =
new rectangle(); s->draw(); s =
new round(); s->draw();}虚函数这么用,只要有一个基类的指针就行了,布布扣,bubuko.com
原文:http://www.cnblogs.com/panpanjy/p/3631423.html