I have a header file that looks like this
// header.hpp
namespace n {
template <typename T>
T someFunc(int some_val);
}
and an implementation that seems to be incorrect:
// body.cpp
#include "header.hpp"
namespace n {
template int someFunc<int>(int some_val) {...}
template bool someFunc<bool>(int some_val) {...}
}
Question: How can I write type-specific implementations in a .cpp-file, if I have the definition of my templated function in the header?
Why do I want this?: In my case, someFunc
calls different functions, depending on the type of T
. So it is not truly generic, which is why I would like to have several implementations (an alternative would be to use this solution)
Sorry, for asking this simple question, but I only found solutions that explain how to store templated class-member-functions in .cpp files (compare post).