Is the following free function implicitly inlined in C++, similar to how member functions are implicitly inlined if defined in the class definition?
void func() { ... }
Do template functions behave the same way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it’s not implicitly inlined. The compiler has no way of knowing if another module will use this function, so it has to generate code for it.
This means, for instance, that if you define the function like that in a header and include the header twice, you will get linker errors about multiple definitions. Explicit
inlinefixes that.Of course, the compiler may still inline the function if it thinks that will be efficient, but it’s not the same as an explicit inlining.
Template functions are implicitly inlined in the sense that they don’t require an
inlineto prevent multiple definition errors. I don’t think the compiler is forced to inline those either, but I’m not sure.