1
我有一個使用兩個參數的簡單模板功能:與模板內聯函數編譯錯誤
template<typename To, typename From>To* asSomething(Common *item)
{
From * tdnItem = downcast(item, From);
To * someClass = NULL;
if(tdnItem != NULL)
{
someClass = downcast(tdnItem->gloo(), To);
}
return someClass;
}
後來,我致電另一聯方法這個輔助方法:
return asSomething<ToFoo, FromFoo>(item);
不過,我得到在Visual Studio中一個奇怪的編譯錯誤:
error C2065: 'FromTmeta' : undeclared identifier
see reference to function template instantiation 'To *asSomething<ToFoo,FromFoo>(Common * *)' being compiled
with
[
To=ToFoo
]
error C2065: 'ToTmeta' : undeclared identifier
函數聲明看起來正確的我,W帽子是這裏的問題嗎?
哪個線(S)做錯誤POI nt到? – immibis 2015-03-18 21:38:34
我看不到編譯器在抱怨的'FromTmeta'符號。在別的地方,還是你在你的示例代碼中重命名它? – 2015-03-18 21:43:07
@immibis第一個錯誤指向'From * tdnItem'聲明。第二個是asSomething(...)調用。 – easythrees 2015-03-18 21:44:25