두 객체의 unordered_map을 포함하는 Scheduler 클래스가 있습니다. 여기C++ unordered_map 해시 함수가 객체를 찾을 수 없습니다.
namespace std {
// does get here
template <>
struct hash<Time>
{
std::size_t operator()(const Time& k) const
{
return ((hash<short>()(k.hr)
^(hash<short>()(k.min) << 1)) >> 1)
^(hash<bool>()(k.morning) << 1);
}
};
}
struct Time {
short hr, min;
bool morning;
// doesnt get here
bool operator==(const Time &other) const
{
return (hr == other.hr && min == other.min
&& morning == other.morning);
}
}
: 여기
void appoint(Time &time, const string activity)
{
Time hashTime(time + incrementor);
schedule.find(hashTime)->second.active = 1; // <-- here
}
내 해시 도구 : 암시 개체가 여기에서 찾을 수 없다는 - 'dereferenceable하지리스트 반복자'
class Scheduler
{
public:
...
private:
unordered_map<Time, Activity> schedule;
}
는 오류가 발생합니다 unordered_map에 존재한다는 증거입니다.
나는 it == schedule.end()
사실이 있음을 확인했습니다.
auto it = schedule.find(hashTime);
if (it == schedule.end()) {
cout << "ok";
}
// this does manage to get found
schedule.insert(make_pair(Time(9, 30, 1), Activity(0,"")));
auto it2 = schedule.find(hashTime);
if (it2 == schedule.end()) {
cout << "ok";
}
지도의 초기 구성이 잘못되었습니다.
Scheduler()
{
Time start(12,0,1); // 12:00am
Time incrementor; // 00:00
Time static_incrementor(0, 15); // 00:15
// creates an empty schedule
// there are 96, 15 min intervals from 12:00am to 11:45pm
for (int i = 0; i < 48; i++) {
Time newTime(start + incrementor);
newTime.morning = true;
cout << newTime.hr << ":" << newTime.min << newTime.morning << endl;
schedule.insert(make_pair(newTime, Activity(0, "")));
incrementor += static_incrementor;
}
Time start2(12, 0, 0); // 12:00pm
Time incrementor2; // 00:00
for (int i = 0; i < 48; i++) {
Time newTime(start2 + incrementor2);
newTime.morning = false;
cout << newTime.hr << ":" << newTime.min << newTime.morning << endl;
schedule.insert(make_pair(newTime, Activity(0, "")));
incrementor2 += static_incrementor;
}
};
'운영자 ==()'은'시간 '에 대해 어떻게 생겼습니까? 질문을 편집해야 [mcve]를 표시 할 수 있습니다. 특히, ** 최소 ** (문제점을 표시하는 가장 작은 예제 프로그램으로 문제점을 줄여야 함) 및 ** 완료 ** (전체 프로그램을 포함해야 함)에 유의하십시오. –
죄송합니다. 당신은'operator ==()'를 가지고 있습니다. 뭐라 구요. –
@WhozCraig : 우리의 의견은 게시물에서 교차되었습니다. –