VC ++编译升级2010-> 2015重新定义; ' constexpr'说明符不匹配

时间:2016-02-24 16:46:21

标签: c++ c++11 stl visual-studio-2015 template-specialization

将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() );
}

1 个答案:

答案 0 :(得分:1)

您是否尝试过将std::less<>类(仿函数)与operator()专门化的常用模式?

E.g:

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