首页 > 解决方案 > main.cpp:28:28: 错误: 'operator[]' 不匹配(操作数类型是'std::unordered_map' 和'line')slopeno[q]++;

问题描述

第 16 行:字符 33:错误:调用 'unordered_map<Solution::line, int>' 的隐式删除的默认构造函数 unordered_map<line,int> slopeno;

main.cpp:28:28: 错误: 'operator[]' 不匹配(操作数类型是'std::unordered_map' 和'line')slopeno[q]++;

`

    #include <bits/stdc++.h>
    using namespace std;
    class line{
        public:
          float slope;
          int xx;
          int yy;
          line(float slope, int xx ,int yy){
              this->slope = slope;
              this->xx = xx;
              this->yy = yy;
          }
    };
    int main()
    {
        vector<vector<int>> points = {{1,1},{3,2},{5,3},{4,1},{2,3},{1,4}};
        int maxa = INT_MIN;
            unordered_map<float,int> slopeno;
            unordered_map<float,int> vertislopeno;
            //save all points in a line in a hashmap by checking every two points
            // traversing the enr=tire array checking every slope
            for(int i=0; i<points.size();i++){
                for(int j=i+1; j<points.size(); j++ ){
                    float slopee;
                    float no = (points [j][0] - points[i][0]) + 0.0;
                    float no2 = (points[j][1] - points[i][1]) + 0.0;
                    if((points[j][1] - points[i][1]) != 0){
                        slopee = no / no2;
                        line q(slopee,points [j][0],points[j][1]) ;
                        slopeno[q]++;  
                        maxa = max(slopeno[q],maxa);
                    }
                    // seperate hashmap for verti lines
                    else{
                        slopee = points[j][1];
                        vertislopeno[slopee]++;  
                        maxa = max(vertislopeno[slopee],maxa);
                    
                    }
                }
        }
        cout<<maxa;
    
        return 0;
    }
    `

请检查导致问题的原因

标签: c++hashmap

解决方案


推荐阅读