Concerning to Inheritance, I want to create concrete Objects from Base Class. As I understand, the Child class can represent it's father class. Considering following classes:
class Material{
public:
virtual void print(){
cout << "Base Material Class" << endl;
}
}
class Wood: public Material{
public:
void print(){
cout << "Wood Material" << endl;
}
}
class Furniture{
public:
void setMaterial(Material material){
this->material = material;
}
virtual void print(){
this->material.print();
}
protected:
Material material;
}
class Chair: public Furniture{
// further code implements here
}
int main(int argc, char** argv){
Chair aChair;
Material material = Wood();
aChair.setMaterial(material);
aChair.print(); // -> "Base Material Class"
}
The question is how to specify material as Wood/Steel/etc... in runtime (This is available in Java but Cpp is not Java). Do you have any suggestion?. I had a look at here and here but I still have not found the solution. Thank you.