为什么这个函数对象不需要指定? [英] why does this function object not need the specified?

查看:159
本文介绍了为什么这个函数对象不需要指定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么这个函数对象不需要指定的类型?

Could any one tell why this function object doesn't need the specified the type?

    class StringPtrTmplLess
{
public:
    template<typename PtrType>
    bool operator()(const PtrType * lhs, const PtrType * rhs)
    {
        return *lhs < *rhs;
    }
};

int main()
{
    set<string*, StringPtrTmplLess> s2;
    return 0;
}

编译器如何知道哪个指定类型将初始化StringPtrTmplLess? / p>

how does the compiler know which specified type it will initialize the StringPtrTmplLess with?

推荐答案

这是因为模板参数扣除,表示模板参数被推导 >从传递给函数调用的参数的类型。这种类型的推导是由编译器完成的。通过链接,详细解释了它。

It is because of template argument deduction which means the template argument is deduced from the type of the argument passed to the function call. This type deduction is done by the compiler. Go through the link which explains it in great detail.

这篇关于为什么这个函数对象不需要指定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆