如何使用struct作为键?

问题描述

我有以下代码,出现了一些错误,例如:

struct duplicatedTurns
    {
        int nodeId;
        int min;
        int max;

        bool operator==(const duplicatedTurns& other) const
        {
            return nodeId == other.nodeId && min == other.min && max == other.max;
        }

I solved it here to following code:
bool operator<(const duplicatedTurns& other) const
{
if (nodeId != other.nodeId) return nodeId < other.nodeId;
if (min != other.min) return min < other.min;
if (max != other.max) return max < other.max;
return false;
}

    };

我要使用的容器:

std::map<duplicatedTurns,int> selected;

在我想在其中插入元素之后:

selected.insert(duplicatedturns{it->nodeId,std::min(it->toLinkId,it->fromLinkId),std::max(it->toLinkId,it->fromLinkId)},"here: increment the number if the key are the same" );

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)