【代码5-1】
class Circle:public (1)
pfivme:
(2) m_circle;
public:
void display()
m_circle. (3) ;
;
【代码5-2】
class Factory
public:
(4) getShapeInstance (int type) //生成特定类实例
switch (type)
case 0:rcturn new Point;
Case l:return new Rectangle;
case 2: return new Line;
case 3: return new Circle;
default: return NULL;
void main (int argo, char *argv[])
if (argc!=2)
cout << "error parameters !" << endl; return; inttype=atoi (argv[1]) ;
Factory factory;
Shape *s;
s = factory. (5) :
if (s==NULL)
cout << "Error get the instance !" << endl;
return;
s->display () ;
(6) ;
return;