However if the function use_fibo() is placed in file a.cpp, after the definition of fibonacci, then it compiles perfectly.
This seems to indicate that in order to use constexpr functions in more than one translation unit, we need to place their definitions in header files with the inline option.
It does make some intuitive sense - the compiler needs to be sure the function is constexpr and will not accept our word for it. Is this why?
This seems to indicate that in order to use constexpr functions in more than one translation unit, we need to place their definitions in header files with the inline option.
Yes, constexpr functions should be declared in a header if you plan on using them from multiple files but you don't need to use the inline keyword. constexpr functions are automatically inline.
It does make some intuitive sense - the compiler needs to be sure the function is constexpr and will not accept our word for it. Is this why?
When you use constexpr on a variable it means the compiler should know its value right there, at compile time, but that is not possible if the value comes from a function that has not been defined yet.