I am using SFINAE to check whether some class has 'print()' function or not. The code works but why calling has_print() is not ambiguous?
class cls {
public:
void print() {
std::cout << "some text" << std::endl;
}
};
template<typename T>
auto has_print(T tt) -> decltype(T().print(), std::true_type()) {
tt.print();
return std::true_type();
}
std::false_type has_print(...) {
std::cout << "Doesn't contain print()" << std::endl;
return std::false_type();
}
int main() {
cls c;
has_print(c);
return 0;
}
It could match both of them.