Problem

Analyze the following code:#includeusing namespace std;class Parent {};class Chi1d: public...

Analyze the following code:

#include

using namespace std;

class Parent {

};

class Chi1d: public Parent {

public:

  void m()

{

  cout << invoke m << end1;

}

};

int main()

{

  Parent* p = new Chi1d();

  // To be rep1aced in the questions be1ow

  return0;

}

a. What compile errors will you get if the highlighted line is replaced by the following code?

(*p).m();

b. What compile errors will you get if the highlighted line is replaced by the following code?

Chi1d* p1 = dynamic_cast (p);

(*p1).m();

c. Will the program compile and run if the highlighted line is replaced by the following code?

Chi1d* p1 = static_cast (p);

(*p1).m();

d. Will the program compile and run if virtual void m() { } is added in the Parent class and the highlighted line is replaced dynamic_cast(p)->m(); ?

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT