我想用SDL_ttf製作一個字體字典,就像我用SDL_image製作字典一樣。由於字體存儲與pnt_size
我做了包含此信息的結構體:在一個函數中找不到Make_Pair標識符,但在另一個函數中找到
struct fontinfo
{
string assetname;
int size;
};
其次是兩個字典:
map<string, SDL_Surface*> imageDictionary;
map<fontinfo*, TTF_Font*> fontDictionary;
兩者之間的區別是,字體字典不僅需要包含字符串到文件,但也是字體的大小。
然後當圖像或字體被對象請求時,它會調用它的get
函數。現在getSprite
正常工作:
SDL_Surface* ResourceManager::getSprite(string assetname)
{
if (assetname == "")
return NULL;
map<string, SDL_Surface*>::iterator it = imageDictionary.find(assetname);
if (it != imageDictionary.end())
return it->second;
else
{
SDL_Surface* image = Load_Image(assetname);
if (image != NULL)
imageDictionary.insert(make_pair(assetname, image));
return image;
}
}
的getFont
方法是除了一個事實,幾乎是相同的,它採用的fontinfo
代替string
:
TTF_Font* ResourceManager::getFont(string assetname, int size)
{
if (assetname == "" || size < 0)
return NULL;
fontinfo* info = new fontinfo();
info->assetname = assetname;
info->size = size;
map<fontinfo*, TTF_Font*>::iterator it = fontDictionary.find(info);
if (it != fontDictionary.end())
return it->second;
else
{
TTF_Font* font = Load_Font(assetname, size);
if (font != NULL)
fontDictionary.insert(make_pair(info, font));
return font;
}
}
編譯器告訴我找不到和標識make_pair
未定義,但僅適用於getFont
的make_pair
函數。 getSprite
中的make_pair
沒有問題。
嗨,這些函數在同一個文件中嗎?它看起來像1文件不是'#include'而另一個文件(或者包含其他東西包含它) –
David
2013-04-29 00:16:58
它們確實在同一個文件中。兩者都來自Class ResourceManager,它們正好在彼此之上。 – M4st3rM1nd 2013-04-29 00:17:57