Hacker News new | past | comments | ask | show | jobs | submit login

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.




You 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.


If 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.


That'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.


Of 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.


I don't understand how that disproves it; your code is not well-formed.


Are you saying that code defined in header files is "not well-formed"?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: