4 ms·
I fail to see how it's more precise. Obviously if the definition is inline, it's duplicated in every point where the declaration is imported. Beginners fail to
by mgaunard 2y ago
I fail to see how it's more precise. Obviously if the definition is inline, it's duplicated in every point where the declaration is imported.
Beginners fail to understand for example that providing a class member function definition within the class definition makes it inline, but that's already what you're doing textually, and that's what the keyword means.
- wolletd 2y agoYou can declare and inline-define a function in a CPP file and you don't need inline because there are no other places that can import it. It's only needed for functions defined in header files where multiple definitions may exist after compiling object files.
- gpderetta 2y agoIf you textually define a function "inline" in an header file yet do not mark it inline, you are duplicating it in every point where the declaration is imported, yet, not being inline for linkage purposes, you will get compilation errors. Member and template functions are special cased to be implicitly inline.
- mgaunard 2y agoThat's not an inline definition, that's a normal definition, which should never be in a header file. Non-inline definitions need to be in their own translation unit.
- gpderetta 2y agoOf course, but that disproves that an "inline definition is a definition that is provided inline with a declaration" [in an header file]. An inline definition is a definition that is marked inline, implicitly or explicitly. Whether it is defined together with the declaration or in an header vs translation unit is immaterial.