Inline const function

Swapnil picture Swapnil · Aug 13, 2015 · Viewed 8k times · Source

As inline function will replace the actual call from code, what is the use of calling inline function as const.

Inline void adddata() const {...}

Answer

Ethan Fine picture Ethan Fine · Aug 13, 2015

An inline function is one which can be defined in each translation unit, and must be defined separately in each translation unit where it is called. It is also a completely non binding suggestion to the compiler that you think the function should be inline. The compiler is free to actually inline or not inline any of your functions, whether or not they are declared inline.

const means that the object the function is a method of will tend not to be visibly modified by the function call. There are exceptions to this, it is always possible to modify if you try hard enough, but in general const is a promise to the caller that you won't.

Using them together means nothing additional to their individual meanings. They are essentially unrelated.