class Computer {
public:
void retail Price(void) {
int p = 2* manufactureCost();
printf( "$%d / n", p); // Print p
}
private:
virtual int manufactureCost(void) {return 1000;}
};
class IBMComputer: public Computer {
private:
virtual int manufactureCost(void) {return 1500;}
};
int main(void) {
Computer *cPtr = new Computer();
IBMComputer *ibmPtr = new IBMComputer();
Computer *cibmPtr = new IBMComputer();
cPtr->retailPrice();
ibmPtr->retailPrice();
cibmPtr->retailPrice();
return 0;
}
This question asks about how the function calls to retailPrice() are evaluated.
a. Explain which version of manufactureCost() is used in the call cibmPtr-> retailPrice() and why.
b. If the virtual keyword is omitted from the declaration of manufacture Cost in the derived class IBMComputer,the preceding code will still compile without error and execute. Will manufacture Cost be implemented as a virtual function in class IBMComputer? Use your knowledge of how C++ is implemented to explain why or why not.
c.It is possible for the private base-class function to be declared public in the derived class. Does this conflict with subtyping principles? Explain why or why not in a few words.