Lỗi này là trong this mã:Strange "Không thể suy ra mẫu đối số cho 'T'" lỗi
//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; });
Lỗi này là:
Error 1 error C2783: 'T ConditionalInput(LPSTR,LPSTR,predicate)' :
could not deduce template argument for 'T' c_main.cpp 17 1
Tôi đã đấu tranh với nó hàng giờ đồng hồ nhưng dường như không tìm được giải pháp. Tôi tin rằng sai lầm có thể là tầm thường, nhưng tôi không thể tìm thấy bất cứ ai khác gặp lỗi trong những hoàn cảnh tương tự. Giúp đánh giá cao!
EDIT: Hiệu chỉnh do Frederik Slijkerman sửa chữa một vấn đề nhưng tạo một vấn đề khác. Lần này, lỗi là:
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
Vui lòng giúp tôi và giúp tôi giải quyết vấn đề này.
Đã chỉnh sửa, vì <> cần được thay thế bằng lt/gt. – Scharron
Câu trả lời đúng trong các ý kiến của câu trả lời ở trên. Mặc dù người dùng này nắm giữ các khoản tín dụng cho nó. – Johnny