2011-08-16 49 views
1

有下面的代码:STL地图实例

class GameTexture 
{ 
private: 
LPDIRECT3DTEXTURE9 texture; 
unsigned char *alphaLayer; 
UINT width, height; 

GameTexture() {}; 
GameTexture(const GameTexture&) {} 
public: 
static GameTexture *CreateTexture(LPCTSTR pSrcFile, LPDIRECT3DDEVICE9 d3dDevice); 

~GameTexture(); 
}; 

class TexturesPool 
{ 
private: 
map<string, GameTexture*> textures; 

,并获得下一

1>c:\program files\microsoft visual studio 10.0\vc\include\xfunctional(125): 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 std::string' 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <' 
1>   c:\program files\microsoft visual studio 10.0\vc\include\xfunctional(124) : while compiling class template member function 'bool std::less<_Ty>::operator()(const _Ty &,const _Ty &) const' 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
1>   c:\program files\microsoft visual studio 10.0\vc\include\map(71) : see reference to class template instantiation 'std::less<_Ty>' being compiled 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
............ 
+1

帖子总结/可能的问题来源>? –

+0

它因为在地图中使用GameTexture *,如果用int替换一切顺利,但我需要用指向我的对象的地图 – Yola

+0

您的代码被粘贴,是正确的。错误可能是由于_textures_变量的错误使用引起的,请查看编译器输出,粘贴错误旁边。 – rodrigo

回答

9

这可能是因为你缺少#include <string>这哪里是失踪operator<应该声明。

一些MSVC的头文件forward-declare std :: string,但实际上并没有包含<string>本身。

+0

构建成功)) – Yola