C++11 C++;std::无序_映射错误(Ubuntu-GCC4.8.2)

C++11 C++;std::无序_映射错误(Ubuntu-GCC4.8.2),c++11,typetraits,xubuntu,gcc4.8,C++11,Typetraits,Xubuntu,Gcc4.8,我正在尝试在linux(Ubuntu)上编译其他人的项目,这是一个使用SDL2的游戏。我正在使用GCC4.8.2和C++11标志使用Code::Blocks进行编译。我花了几个小时在网上查找错误,甚至理解错误,但一点运气都没有。我希望任何人都能帮助我,或者至少给我一个线索 错误是: /usr/include/c++/4.8/bits/hashtable_policy.h: In instantiation of ‘struct std::__detail::__is_noexcept_hash&

我正在尝试在linux(Ubuntu)上编译其他人的项目,这是一个使用SDL2的游戏。我正在使用GCC4.8.2和C++11标志使用Code::Blocks进行编译。我花了几个小时在网上查找错误,甚至理解错误,但一点运气都没有。我希望任何人都能帮助我,或者至少给我一个线索

错误是:

/usr/include/c++/4.8/bits/hashtable_policy.h: In instantiation of ‘struct std::__detail::__is_noexcept_hash<Position, PositionHash>’:
/usr/include/c++/4.8/type_traits:121:12:   recursively required from ‘struct std::__and_<std::is_default_constructible<PositionHash>, std::is_copy_assignable<PositionHash>, std::__detail::__is_noexcept_hash<Position, PositionHash> >’
/usr/include/c++/4.8/type_traits:121:12:   required from ‘struct std::__and_<std::__is_fast_hash<PositionHash>, std::is_default_constructible<PositionHash>, std::is_copy_assignable<PositionHash>, std::__detail::__is_noexcept_hash<Position, PositionHash> >’
/usr/include/c++/4.8/type_traits:127:38:   required from ‘struct std::__not_<std::__and_<std::__is_fast_hash<PositionHash>, std::is_default_constructible<PositionHash>, std::is_copy_assignable<PositionHash>, std::__detail::__is_noexcept_hash<Position, PositionHash> > >’
/usr/include/c++/4.8/bits/unordered_map.h:99:66:   required from ‘class std::unordered_map<Position, SDLGameObject*, PositionHash>’
/home/*/*/games/magictower/Magic-Tower/Floor.h:17:61:   required from here
提前感谢

你有这个吗

std::unordered_map<Position, SDLGameObject*, PositionHash>
使用
Poisition
指针

映射将把键(一个
位置
值)传递给散列函数,但散列函数不接受值(或引用),它接受一个指针,这就是错误的来源。将哈希函数改为引用:

std::size_t operator()(const Position& p) const

这是有道理的。。。谢谢你的解释。我稍后会在家里测试,非常感谢。我会告诉你事情的经过!它工作得很好,PositionHash的最终代码是:std::size_t operator()(const Position&p)const,正如您所说,返回部分是:return p.x_coord*16+p.y_coord;谢谢
std::unordered_map<Position, SDLGameObject*, PositionHash>
std::size_t operator()(const Position* p) const
std::size_t operator()(const Position& p) const