Avoid Redundant Inline Declarations

Remember that functions defined inside the class definition are implicitly inline. Therefore, the inline keyword is redundant in the definition of the member function of the following class:

 class Employee{public: inline const string& name() const {return _name;}private string _name;};

The inline specifier is innocuous in this example. However, it can become a maintenance problem if you move the definition of name() outside the class and extend it with more functionality (for example, if you convert the string to uppercase before returning it to the caller). You are likely to forget that the member function is still declared inline, although it shouldn’t be.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: