這裏是代碼和錯誤消息,爲什麼?我試過刪除這行代碼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相關的對有關? –