Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Expanding on Q2, create a function that takes a Shape object by value and try to upcast a derived object in as an argument. See

 Expanding on Q2, create a function that takes a Shape object by value and try to upcast a derived object in as an argument. See what happens. Fix the function by taking a reference to the Shape object. HERE IS Q2 #include  using namespace std; class Shape { public: virtual void draw() = 0; // pure virtual function }; class Circle : public Shape { void draw() { cout << "Drawing Circle "; } }; class Square : public Shape { void draw() { cout << "Drawing Square "; } }; class Triangle : public Shape { void draw() { cout << "Drawing Triangle "; } }; int main() { // creating pointers for base class Shape* s[5]; // creating objects for child class Circle* c = new Circle(); Square* sq = new Square(); Triangle* t = new Triangle(); // peforming upcasting s[1] = c; s[2] = sq; s[3] = t; // calling draw s[1]->draw(); s[2]->draw(); s[3]->draw(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

3. Which nonverbal behaviors, if any, are universal?

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago