//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
그러나 해결책을 찾는 것처럼 보이지는 않습니다. 나는 실수가 사소한 것이라고 믿지만 유사한 상황에서 다른 누구도 오류가 발생하는 것을 발견 할 수 없었다. 많은 도움을 주셨습니다.
편집 : Frederik 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
이 문제를 해결할 수 있도록 도와주십시오.
row = ConditionalInput<int>(...)
<>가 lt/gt로 대체되어야하므로 편집되었습니다. – Scharron
위의 답변에 대한 답변에서 정답입니다. 이 사용자는 크레딧을 보유하고 있지만 – Johnny