Consider the following code fragment: class Object { public: virtual void printM
ID: 3648590 • Letter: C
Question
Consider the following code fragment:class Object
{ public: virtual void printMe() = 0; };
class Place : public Object
{ public: virtual void printMe() { cout << "Buy it. "; } };
class Region : public Place
{ public: virtual void printMe() { cout << "Box it. "; } };
class State : public Region
{ public: virtual void printMe() { cout << "Ship it. "; } };
class Maryland : public State
{ public: virtual void printMe() { cout << "Read it. "; } };
int main() {
Region* mid = new State;
State* md = new Maryland;
Object* obj = new Place;
Place* usa = new Region;
md->printMe();
mid->printMe();
(dynamic_cast<Place*>(obj))->printMe();
obj = md;
(dynamic_cast<Maryland*>(obj))->printMe();
obj = usa;
(dynamic_cast<Place*>(obj))->printMe();
usa = md;
(dynamic_cast<Place*>(usa))->printMe();
return EXIT_SUCCESS;
}
What is the output from calling the main function of the Maryland class?
Explanation / Answer
Read it Ship it Box it Read it Ship it Read it the 4th cast operator won't work i think.. due to non IS_A relationship..
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.