Question: Consider the following code fragment: class Object { public: virtual void printMe() = 0; }; class Place : public Object { public: virtual void printMe()
Consider the following code fragment:
class Object
{ public: virtual void printMe() = 0; };
class Place : public Object
{ public: virtual void printMe() { cout << "Buy it.\n"; } };
class Region : public Place
{ public: virtual void printMe() { cout << "Box it.\n"; } };
class State : public Region
{ public: virtual void printMe() { cout << "Ship it.\n"; } };
class Maryland : public State
{ public: virtual void printMe() { cout << "Read it.\n"; } };
int main() {
Region* mid = new State;
State* md = new Maryland;
Object* obj = new Place;
Place* usa = new Region;
md−>printMe();
mid−>printMe();
(dynamic cast(obj))−>printMe();
obj = md;
(dynamic cast(obj))−>printMe();
obj = usa;
(dynamic cast(obj))−>printMe();
usa = md;
(dynamic cast(usa))−>printMe();
return EXIT SUCCESS;
}
What is the output from calling the main function of the Maryland class?
Step by Step Solution
3.46 Rating (166 Votes )
There are 3 Steps involved in it
corrected program First add following header files in your code ... View full answer
Get step-by-step solutions from verified subject matter experts
