的錯誤是在this代碼:聊齋志異「無法推導出模板參數的‘T’」的錯誤
//myutil.h
template <class T, class predicate>
T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, predicate condition);
//myutil.cpp
template <class T, class Pred>
T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, Pred condition)
{
T input
cout<< inputMessage;
cin>> input;
while(!condition(input))
{
cout<< errorMessage;
cin>> input;
}
return input;
}
...
//c_main.cpp
int row;
row = ConditionalInput("Input the row of the number to lookup, row > 0: ",
"[INPUT ERROR]: Specified number is not contained in the range [row > 0]. "
"Please type again: ", [](int x){ return x > 0; });
的錯誤是:
Error 1 error C2783: 'T ConditionalInput(LPSTR,LPSTR,predicate)' :
could not deduce template argument for 'T' c_main.cpp 17 1
我一直在掙扎了好幾個小時但似乎無法找到解決方案。我相信錯誤可能是微不足道的,但在類似情況下,我找不到其他人遇到錯誤。 非常感謝!
編輯:由弗雷德裏克Slijkerman作出修正解決一個問題而造成另一種。這一次的錯誤是:
Error 1 error LNK2019: unresolved external symbol "int __cdecl ConditionalInput<int,class `anonymous namespace'::<lambda0> >(char *,char *,class `anonymous namespace'::<lambda0>)" ([email protected]<lambda0>@[email protected]@@@YAHPAD0V<lambda0>@[email protected]@@Z) referenced in function _main
請耐心和我一起幫我解決這個問題。
已編輯,因爲<>需要替換爲lt/gt。 – Scharron 2010-07-24 10:14:46
上述答案的評論中的正確答案。雖然這個用戶持有它的信用。 – Johnny 2010-07-24 10:20:38