gpt4 book ai didi

visual-studio - 如何将 binary_function 更改为 c++17 代码?

转载 作者:行者123 更新时间:2023-12-05 02:11:38 31 4
gpt4 key购买 nike

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

我尝试通过谷歌搜索但找不到解决方案。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

最佳答案

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

如果您需要代码在 C++17 之前仍然有效,请将这些添加到您的类中:

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

关于visual-studio - 如何将 binary_function 更改为 c++17 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57236763/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com