Why-does-inheritance-increase-class-size-in-C? tccicomputercoaching.com

Page 1

Why-does-inheritance-increase-class-sizein-C? tccicomputercoaching.com

Inheritance reuses code. So the overall effect is to reduce the compiled code size less than 2x for a base class and an inherited class. Only what is new in the inherited class adds code to the compiled binary, only data members added to the inherited class increase the instance data size.

An inherited class “contains” all the necessary code and data of the base class, plus whatever is unique to the inherited class. But “contains” is not copies, it is referenced with a few bytes and function dispatch table entries. This is the advantage of inheriting code over rewriting the same code for an only slightly different class, destined to be used primarily for the same purpose and in the same manner as the base class. But in the modern age size of class recipe in the compiled code is not really a concern usually.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.