Joh*_*nny 6 c++ lambda templates functional-programming
错误在此代码中:
//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; });
Run Code Online (Sandbox Code Playgroud)
错误是:
Error 1 error C2783: 'T ConditionalInput(LPSTR,LPSTR,predicate)' :
could not deduce template argument for 'T' c_main.cpp 17 1
Run Code Online (Sandbox Code Playgroud)
我一直在努力工作几个小时,但似乎无法找到解决方案.我认为错误可能是微不足道的,但在类似情况下我找不到其他人遇到错误.非常感谢!
编辑:Frederik Slijkerman所做的更正解决了一个问题,但创造了另一个问题.这次错误是:
Error 1 error LNK2019: unresolved external symbol "int __cdecl ConditionalInput<int,class `anonymous namespace'::<lambda0> >(char *,char *,class `anonymous namespace'::<lambda0>)" (??$ConditionalInput@HV<lambda0>@?A0x109237b6@@@@YAHPAD0V<lambda0>@?A0x109237b6@@@Z) referenced in function _main
Run Code Online (Sandbox Code Playgroud)
请耐心帮我解决这个问题.
| 归档时间: |
|
| 查看次数: |
7358 次 |
| 最近记录: |