为什么调用该函数在 SFINAE 中没有歧义?

Why calling the function isn't ambiguous in SFINAE?

我正在使用 SFINAE 检查某些 class 是否具有 'print()' 功能。代码有效,但为什么调用 has_print() 没有歧义?

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.

overload resolution中,第一个重载胜过第二个带省略号参数的重载。

  1. A standard conversion sequence is always better than a user-defined conversion sequence or an ellipsis conversion sequence.