如何将binary_function更改为C ++ 17代码?

时间:2019-07-27 23:17:48

标签: visual-studio refactoring c++17

我注意到在c ++ 17中binary_function被删除了。而且我不知道如何解决它。有人可以帮我改变结构吗?谢谢

我尝试通过Google搜索,但找不到解决方案。 Visual Studio 2019,c ++ 17

struct FGuildCompare : public std::binary_function<CGuild*, CGuild*, bool>
{
    bool operator () (CGuild* g1, CGuild* g2) const
    {
        if (g1->GetLadderPoint() < g2->GetLadderPoint())
            return true;
        if (g1->GetLadderPoint() > g2->GetLadderPoint())
            return false;
        if (g1->GetGuildWarWinCount() < g2->GetGuildWarWinCount())
            return true;
        if (g1->GetGuildWarWinCount() > g2->GetGuildWarWinCount())
            return false;
        if (g1->GetGuildWarLossCount() < g2->GetGuildWarLossCount())
            return true;
        if (g1->GetGuildWarLossCount() > g2->GetGuildWarLossCount())
            return false;
        int c = strcmp(g1->GetName(), g2->GetName());
        if (c>0)
            return true;
        return false;
    }
};

std :: binary_function已删除

1 个答案:

答案 0 :(得分:2)

所有添加的std::binary_function都是三个typedef。并且(在许多情况下)现在可以推断出这些类型。只需从std::binary_function中删除继承即可。

如果您需要代码仍能在C ++ 17之前运行,请将它们添加到您的课程中:

    typedef CGuild*   first_argument_type;
    typedef CGuild*   second_argument_type;
    typedef bool      result_type;