的错误是在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