c++ - 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;
}
`
请检查导致问题的原因
解决方案
推荐阅读
- windows - Spark结构化流式writeStream到控制台问题
- python - 将无类型的 python dict() 转换为对象的类型化字典
- spring - Spring Boot 不会在 Mysql 上自动创建数据库表
- python - 为什么一行中的多个列表值分配不会改变列表中的相应值?
- c# - Blazor 使元素在 x 秒后消失
- javascript - Node.js Express.js Mongoose 错误 [ERR_HTTP_HEADERS_SENT]:在将标头发送到客户端后无法设置标头
- hyperledger-fabric - 将结构从 1.4.4 升级到 2.2 时出现问题
- django - 在生产中在 Django 3 中实现自定义 404 页面的正确方法
- flutter - 如何从烧瓶 API 接收 http.MultipartRequest 响应中的图像文件?
- reactjs - 将firebase通知定向到reactjs应用程序内部