0
我試圖從我的config.lua文件中用C++獲取一個變量。 我從一個教程中創建一個Lua-Class,以獲得這些變量,但我'得到一個錯誤 當我嘗試打電話給誰從config.lua得到可變C++錯誤:沒有函數模板的實例
這裏的代碼片段的功能:
LuaScript script("config.lua");
script.get(string("test"));
我'得到的錯誤,「沒有函數模板實例參數列表匹配」,在那裏我稱之爲點「script.get(字符串(」測試));」
模板功能和專業化看起來像這樣:
template<typename T>
T get(const std::string &variableName)
{
if (!L)
{
printError(variableName, "Script not loaded");
return lua_getdefault<T>();
}
T result;
if (lua_gettostack(variableName))
{
result = lua_get<T>(variableName);
}else{
result = lua_getdefault<T>();
}
clean();
return result;
}
專業化:
template<>
inline std::string LuaScript::lua_get<std::string>(const std::string &variableName)
{
std::string s = "null";
if (lua_isstring(L, -1))
{
s = std::string(lua_tostring(L, -1));
}else{
printError(variableName, "Not a string");
}
return s;
}
只是一些更多的信息,我'編碼和使用Visual Studio 2012
感謝您的幫助:)
'LuaScript :: lua_get' **不是專業化的**函數模板('get()')顯示。 –
所以我需要寫一個專業化或是我的錯誤在別的地方?因爲get()函數調用lua_getdefault – chrisoo
誰downvoted,爲什麼downvote? OP沒有說專業化是爲get();他們正確地顯示了字符串lua_get的專業化,因爲那是他們認爲正在實例化(但不是,根據我的答案)。 –
Schollii