How to avoid overhead of the function using inline C++ functions2 min read

Making a function inline avoids the overhead of a function call. By default functions defined inside a class are inline. To get the benefits of making a function inline, function defined outside the class can also be made inline. Syntax for defining a function as inline is as follow:

Consider the following example which demonstrate inline member functions:

Input and output for the above program is as follows:

Memory Allocation for Classes and Objects

Class is not allocated any memory. This is partially true. The functions in a class are allocated memory which are shared by all the objects of a classes. Only the data in a class is allocated memory when an object is created. Every object has its own memory for data (variables). For example consider the following Student class and its function:

Take your time to comment on this article.

Leave a Comment