在将VC++项目从VS2010编译器升级到VS2015编译器的过程中,我遇到了此错误,我们将不胜感激。

C2475 'std::less<_Kty>::operator ()': redefinition; 'constexpr' specifier mismatch

这是生成错误的代码:
bool std::less < sp < ref::db::string > >::operator()(
    const sp < ref::db::string >& first,
    const sp < ref::db::string >& second ) const
{
    return first->cpp() < second->cpp();
}

第二个示例错误:
'std::less<sp<ref::ifile>>::operator ()': redefinition; 'constexpr' specifier mismatch

码:
template <>
bool std::less < sp < ref::ifile > >::operator()(
    const sp < ref::ifile >& x,
    const sp < ref::ifile >& y ) const
{
    if( std::tolower( x->name()->cpp() )
        == std::tolower( y->name()->cpp() ) )
    {
        return std::tolower( x->extention()->cpp() )
               < std::tolower( y->extention()->cpp() );
    }

    return std::tolower( x->name()->cpp() ) < std::tolower( y->name()->cpp() );
}

最佳答案

您是否尝试过使用std::less<>专门化operator()类(functor)的通常模式?

例如。:

namespace std
{

template<>
struct less<sp<ref::db::string>>
{
    bool operator()(const sp<ref::db::string>& first,
                    const sp<ref::db::string>& second) const
    {
        // Your custom std::less implementation code ...

        return first->cpp() < second->cpp();
    }
};

} // namespace std

关于c++ - VC++编译器升级2010-> 2015重新定义; 'constexpr'说明符不匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35608092/

10-15 06:39