I wanted to write a template combination of 2 overloads, as shown in the code below, I wish to do different process on 2 genres of objects. when compile I got these errors:
// Error C2672 'info': no matching overloaded function found
// and
// // Error C2783 'void info(StrType)': could not deduce template argument for '__formal'
code is:
/// With this commented out, compile fails, while with it uncommented, all cals get
// in to this void template.
//template<typename T/*,
//typename = void*/>
//void info(T s) {
//
//}
template <typename StrType,
std::enable_if_t<std::is_convertible_v<std::string, StrType>, bool> = false
>
void info(StrType s) {
std::cout <<"str: "<< s << std::endl;
}
template<typename IntType,
std::enable_if_t<std::is_same_v<
typename std::remove_reference_t<typename std::remove_cv<IntType>> ,
int
>, bool> = false
>
void info(IntType s) {
std::cout <<"int: "<< s + s << std::endl;
}
int main() {
info("31"); // Error C2672 'info': no matching overloaded function found
// and
// // Error C2783 'void info(StrType)': could not deduce template argument for '__formal'
info((int)111); // Same complain as above.
}
I was expecting the output be str: 31 int: 111 but compiling failed, complaining: Error C2672 'info': no matching overloaded function found