xstdde错误"无法推断模板参数..."

时间:2015-12-29 20:37:04

标签: c++ runtime-error sfml

我正在研究小行星游戏副本。我得到的这个错误超出了我的理解,所以我希望你可以提供帮助。

在我的代码中,我有一个类名asteroid,用于存储每个小行星对象。在这个课程中,我有一个名为create()的公共函数,其参数为sf::ConvexShape(如果你不知道sf::ConvexShape是什么,它是一个函数SFML库)。我还有一个std::map<asteroid, sf::ConvexShape>来存储小行星对象作为键,它们的形状为.second

错误是运行时错误,编译器中的一切都很好。错误报告对我来说是胡言乱语,但有一部分提到了#34; iterator&#34;和&#34; std :: vector&#34;这让我觉得我做错了将迭代器传递给create()函数?

以下是错误日志:

Error 5 error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 10 error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 12 error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 9 error C2784: 'bool std::operator <(const std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 8 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 6 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 4 error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 11 error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 7 error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const asteroid' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

Error 13 error C2676: binary '<' : 'const asteroid' does not define this operator or a conversion to a type acceptable to the predefined operator C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 180 1 SFML testing

还有酱here

为什么我会收到这些错误?我该如何解决?

如果有什么我忘了提及,请告诉我,当我不明白这个问题时很难知道该问什么。

1 个答案:

答案 0 :(得分:1)

std::map按排序顺序存储内容。如果您没有告诉它如何排序,它将使用operator <。你的问题是:

 asteroid a, b;
 a < b; // Not defined.

您需要以下内容:

 bool operator <( const asteroid& lhs, const asteroid& rhs)
 {
     ????
 }

除了你不能使用该位置(因为它不断变化)。也许你应该这样做:

 class asteroid
 {
     static unsigned global_id;
     unsigned id;
     .... // Previous contents as before.
 }

 asteroid::asteroid() : id (global_id++) { ... }

然后

 bool operator <( const asteroid& lhs, const asteroid& rhs)
 {
     lhs.id < rhs.id;
 }