I have this class:
class Pizza{
protected:
string desc;
public:
Pizza(){
desc = "unknown pizza";
}
virtual string getdesc(){
return desc;
}
virtual double cost(){
return 0;
}
};
And one of its subclass:
class Small: public Pizza{
public:
Small(){
desc = "Small";
}
double cost(){
return 8.00;
}
};
Besides the "Small" class there are others that are similar, eg. "Medium", "Large", etc.
I want to implement a Factory class for this. However, it doesnt seem to work:
class PizzaFactory: public Pizza{
public:
Pizza* getPizzaInstance( int id );
};
Pizza* PizzaFactory::getPizzaInstance( int id ) {
switch (id) {
case 1:
return new Small();
case 2:
return new Medium();
default:
return NULL;
}
}
I wonder why when i called in main, it does not give me error but the "id" parameter does not get included into the switch statement.
Any help would be much appreciated.