标签:test bsp oid this print dynamic draw 绑定 程序
class Shape{ public: enum ShapeColor{ Red, Green, Blue = 1, Org }; void printColor(){ cout << Red << Green << Blue << Org << endl; } virtual void draw(ShapeColor color = Red)const = 0; }; class Rectangle :public Shape{ public: virtual void draw(ShapeColor color = Green) const{ cout << "this is rectangle,color is " << color << endl; } }; class Circle :public Shape{ public: virtual void draw(ShapeColor color)const{ cout << "this is circle,color is " << color << endl; } }; static void test(){ Shape *ps; Shape *pc = new Circle; Shape *pr = new Rectangle; pc->draw(); pr->draw(); } 默认参数是静态绑定,pr输出值仍然是Shape的默认值
标签:test bsp oid this print dynamic draw 绑定 程序
原文地址:http://www.cnblogs.com/tla001/p/6702029.html