Advantages and disadvantages of using macro and inline functions - C++

Advantages and disadvantages of using macro and inline functions.

- A textual substitution is provided by a macro as a constant, where as an inline function is procedure which is called at each time. Although the macros have few advantages over inline functions, the disadvantages are numerous. For example, a macro can not perform type checking and validation, as these operations are performed in a function at the most.

- Everyone should decide for themselves to use them, but the use of inline functions over macros is advocated by Bjarne Struoustrup, the creator of C++. The imperative features of inline functions are frequently used with classes in C++. There is similarity between invoking normal functions and inline functions, except that, inline functions are never actually called. The inline functions, as their name suggests, are expanded in line at every time of invocation. All that is needed to invoke an inline function is to prefix the key word ‘inline’ to the function.
What are ways to avoid memory leaks?
What are ways to avoid memory leaks? - A memory leak is the effect of running out of memory....
Difference between dynamic and static casting
Difference between dynamic and static casting - static_cast are used in two cases:1) for implicit casts that the compiler would make automatically anyway (bool to int) 2) as a mandatory forced cast (float to int)....
Describe static and dynamic binding of functions - C++
Describe static and dynamic binding of functions - By default, matching of function call with the correct function definition happens at compile time......
Post your comment