STL映射实例化

时间:2011-08-16 13:21:01

标签: c++ 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 :(得分:9)

您可能遗漏了#include <string>,而operator<应该宣告失踪的<string>

某些MSVC的头文件正向声明std :: string,但实际上并不包含{{1}}本身。