BigData小白 2021-12-31 11:14 采纳率: 100%
浏览 736
已结题

不存在用户定义的从"std::pair<int,int>"到"point_t"的适当转换(point_t是struct结构体的名字)

typedef struct point
{
    int row;
    int col;
}point_t;

point_t actionAI(ChessData* data)
{
    calcScore(data);

    int maxScore = 0;
    std::vector<std::pair<int, int> > maxPoints;//容器

    int k = 0;

    for (int row = 0; row < BOARD_GRAD_SIZE; row++)
    {
        for (int col = 0; col < BOARD_GRAD_SIZE; col++)
        {
            if (data->chessMap[row][col] == 0)
            {
                if (data->scoreMap[row][col] > maxScore)
                {
                    maxPoints.clear();
                    k = 0;
                    maxPoints.push_back(std::make_pair(row, col));
                    k++;
                }
                else if (data->scoreMap[row][col] == maxScore)
                {
                    maxPoints.push_back(std::make_pair(row, col));
                    k++;
                }
            }
        }
    }

    srand((unsigned)time(0));
    int index = rand() % k;
    return maxPoints[index];
//返回报错,不存在用户定义的从"std::pair<int,int>"到"point_t"的适当转换(point_t是struct结构体的名字)
}
  • 写回答

1条回答 默认 最新

  • stone_wangzx 2021-12-31 11:41
    关注

    给point添加对应的构造函数试试

    
    typedef struct point
    {
        int row;
        int col;
    
        point() {}
    
        point(std::pair<int, int> data) {
            row = data.first;
            col = data.second;
        }
    
    }point_t;
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月8日
  • 已采纳回答 12月31日
  • 创建了问题 12月31日

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统