I am working on a C ++ Primer (5th Edition), and while this is really great stuff, I have found that in some cases I come across explanations that give me more questions than answers.
In the current example (highlighted in bold):
Unlike other functions, inline and constexpr functions can be defined several times in a program. In the end, to extend the code, the compiler needs a definition, not just a declaration. However, all definitions of a given inline or constexpr must match exactly . As a result, inline and constexpr functions are usually defined in headers.
I worked a bit on this and I saw many answers that I can define an inline function several times , as long as the definition is identical. In addition, I saw that the standard allows this. I'm curious: why?
Is there a possible encoding situation in which I will have #include for a given header file for the built-in function that I want, just to provide a duplicate definition in my .cpp file? I feel that I am missing an obvious situation where this rule applies. Why not just make it so that you can only define the built-in function once in the header, period and not worry about it later?
All the best.
source share