As templates need to be defined in header files so the compiler can instantiate them I find myself hiding my implemention details in a *.tcc file at the end of the "main" header. Which means the implementation details will be included by any module that includes my header.
So I would need them to be inline to avoid odr-violations. Now I know that in-class definition of class methods automatically makes them inline. Does that mean that if I define them outside of the class I still need to manually add the specifier? Also I found this IBM documentation that says I might as well specify the in-class declarations inline which would also implicitely make the definitions inline:
An equivalent way to declare an inline member function is to either declare it in the class with the inline keyword (and define the function outside of its class) or to define it outside of the class declaration using the inline keyword.
Is that correct?
/* myheader.hpp */
#include <cstdio>
#include <utility>
template <typename T>
class myclass
{
myclass(T);
auto print() -> void;
T val_;
};
#inlcude "myheader.tcc"
/* myheader.tcc */
template <typename T>
/* inline? */ myclass<T>::myclass(T val)
: val_{ std::move(val) }
{ }
template <typename T>
/* inline? */ auto myclass<T>::print() -> void
{
printf("There are 10 types of people in this world, those who understand binary and those who dont!\n");
}