while I am learning Prototype design online, I got a code but it looks error from my side, can someone please check and confirm it
class Stooge {
public:
virtual Stooge* clone() = 0;
virtual void slap_stick() = 0;
};
class Curly : public Stooge {
public:
Stooge* clone() { return new Curly; }
void slap_stick() {
cout << "Curly: suffer abuse\n"; }
};
Stooge* Factory::s_prototypes[] = {
0, new Larry, new Moe, new Curly
};
Stooge* Factory::make_stooge( int choice = 3 ) {
return s_prototypes[choice]->clone();
}
"make_stooge" in Factor creates two object or not? because
s_prototypes[choice] returns one object and s_prototypes[choice]->clone() again returns another object.
Aucun commentaire:
Enregistrer un commentaire