这里是代码和错误消息,为什么?我试过删除这行代码Building t = beginEndMap[b.id];
后,编译就OK了。但是无法弄清楚这条线路的错误。这一行不是对相关的,但编译错误是对关联的。有关C++ std :: pair的怪异编译错误
错误消息,
Error:
required from 'std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::tuple<_Args1 ...>, std::tuple<_Args2 ...>) [with _Args1 = {const int&}; _Args2 = {}; _T1 = const int; _T2 = Building]'
源代码,
struct Building {
int id;
int pos;
int height;
bool isStart;
Building(int i, int p, int h, int s) {
id = i;
pos = p;
height = h;
isStart = s;
}
};
class Solution {
public:
vector<pair<int, int>> getSkyline(vector<vector<int>>& buildings) {
vector<Building> sortedBuilding;
unordered_map<int, Building> beginEndMap;
vector<pair<int, int>> result;
for (Building b : sortedBuilding) {
Building t = beginEndMap[b.id];
}
return result;
}
};
int main() {
}
但我的'key_type'比'Building',请参阅定义''是其他int' unordered_map beginEndMap',和你的意思'value_type'以外'为key_type '? –
@ LinMa我不好。 'value_type'。我纠正了它。 – bolov
谢谢,您的回复对我有意义,但为什么编译错误与unsorted_map相关的对有关? –