I know the root cause why you can't find the element which it should.
Do you use staic variale in you Hash
function.
Change you Hash
function to like this:
struct Hash
{
size_t operator()(Play* const &x) const
{
size_t t = 0;
string u = x->getOffense();
string v = x->getDefence();
string w = x->getPlayDesc();
t = u.length() + v.length() + w.length();
return t;
}
};
This function has problem, when the same object A
call this function twice, the result is different. Because you use a static variable static int hash = 0;
. So in your case when you construct the hashedData
, the function Hash
call once, when you use find
function, the same object call Hash
again, but you got different result, so the funtiocn find
return hashedData.end()
.
when you call cout << (*got)->getSummary() << endl << endl;
, you will meet a seg fault.
you should do like this:
for (int i = 0; i < 10; ++i)
{
got = hashedData.find(data[i]);
if (got != hashedData.end())
{
cout<<(*got)->getSummary()<<endl;
}
}