The following code could not compile due to error: redefinition of 'template<class Integer, class> void func(Integer)'
#include <iostream> #include <type_traits> template<typename Float, typename = typename std::enable_if<std::is_floating_point<Float>::value>::type> void func(Float floatVal) { std::cerr << "float: " << floatVal << "\n"; } template<typename Integer, typename = typename std::enable_if<std::is_integral<Integer>::value>::type> void func(Integer integer) { std::cerr << "integral: " << integer << "\n"; } int main() { func(32.4246); func(144532); }
But the two functions will obviously have different signatures when instantiating. So why is it impossible to compile?
Pay attention . I know how to fix this: simply adding another layout template parameter to one of the functions, for example. typename=void , will work as here
template<typename Integer, typename dummy=void, typename = typename std::enable_if<std::is_integral<Integer>::value>::type> void func(Integer integer){}
But why should I do this?
source share