Search code examples
c++inlining

Do I have to repeat the inlined keyword on function implementation


I always try to keep implementation outside of headers, so for templates and inlined functions, I usually do something like this


// File.h
inline bool foo()

#include "File.hpp"

// File.hpp

inline bool foo()
{
    return 1;
}

My question is, what does the C++ specification have to say about repeating the inline keyword for the actual implementation of the function? (as shown in this example)

I don't really want to do that as it gets messy with lots and lots of functions, and while my compiler doesn't complain, I wonder if the compiler still accepts the inline hint.

Anyone know?


Solution

  • I tend to put inline as far from the interface as possible since it is an implementation detail and not part of the interface. Hence: omit the first inline in the declaration. And only attach it to the function definition. For the inclusion of an hpp compiler scopes are irrelevant in respect to inline since the files are treated as concatenated. See also http://www.parashift.com/c++-faq/where-to-put-inline-keyword.html for a more detailed explanation.