【发布时间】:2013-04-24 20:21:21
【问题描述】:
我需要你的帮助来参数化具有 int 值的模板。
看起来是这样的:
SpriteSwitcher.h:
template<int N >
bool initWithFilesArray(std::string (&fileNames)[N],int width, const CCPoint position);
SpriteSwitcher.cpp:
template<int N >
bool SpriteSwitcher::initWithFilesArray(std::string (&fileNames)[N], int width, const CCPoint position)
{
return true;
}
然后我尝试用我的 initWithFileArray 函数初始化 SpriteSwitcher 类
std::string g[2] = {"hello", "world"};
SpriteSwitcher *s = new SpriteSwitcher();
s->initWithFilesArray(g, visibleSize.width, origin);
我收到以下错误:
error lnk2019 无法解析的外部符号“”public: bool __thiscall SpriteSwitcher::initWithFilesArray(class std::basic_string,class std::allocator > (&)[2],int,class cocos2d::CCPoint)” (??$initWithFilesArray@$01@SpriteSwitcher@@QAE_NAAY01V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HVCCPoint@cocos2d@@@Z)" 在 Funktion ""public: virtual bool __thiscall MenuScreen::init(void)" (?init@MenuScreen@@UAE_NXZ)"。
谁能帮助我,告诉我问题出在哪里?
【问题讨论】:
-
你的问题不在于类型推导。您得到的是链接器错误。查看链接的问答
标签: c++ arrays templates c++11 parameters