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();
}