Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a small program to show the difference between calling a virtual function inside a normal member function and calling a virtual function inside

Write a small program to show the difference between calling a virtual function inside a normal member

Write a small program to show the difference between calling a virtual function inside a normal member function and calling a virtual function inside a constructor. The program should prove that the two calls produce different results. Create a class that has a data member and a derived class that adds another data member. Write a non-member function that takes an object of the base class by value and prints out the size of that object using sizeof. In main() create an object of the derived class, print out its size, and then call your function. Explain what happens. Create a simple example of a virtual function call and generate assembly output. Locate the assembly code for the virtual call and trace and explain the code. Write a class with one virtual function and one non-virtual function. Inherit a new class, make an object of this class, and upcast to a pointer of the base-class type. Use the clock() function found in (you'll need to look this up in your local C library guide) to measure the difference between a virtual call and non-virtual call. You'll need to make multiple calls to each function inside your timing loop in order to see the difference.

Step by Step Solution

3.40 Rating (162 Votes )

There are 3 Steps involved in it

Step: 1

C include class Base public Base callVirtualFunction Call v... 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

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Computer Network questions