本文共 1199 字,大约阅读时间需要 3 分钟。
class Rectangle {public: virtual void SetWidth(int w) { mWidth = w; } virtual void SetHeigth(int h) { mHeigth = h; } virtual int GetArea() { return mWidth * mHeigth; }protected: int mWidth; int mHeigth;};class Square extends Rectangle {public: virtual void SetWidth(int w) { mWidth = w; mHeigth = h; } virtual void SetHeigth(int h) { mHeigth = h; mWidth = w; }};
Rectangle* RecFactory::GetInstance();//(static)
Rectangle* rec = RecFactory.GetInstance();rec->SetWidth(10);rec->SetHeigth(20);int area = rec->GetArea();
转载地址:http://xdeqj.baihongyu.com/