T Conditi...">

Strange "Failed to print template argument for error" T "

The error is in this code:

//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:

Error   1       error C2783: 'T ConditionalInput(LPSTR,LPSTR,predicate)' :
could not deduce template argument for 'T' c_main.cpp        17      1

I struggled with this watch, but didn't seem to find a solution. I believe that the error may be trivial, but I could not find anyone who would encounter the error in such circumstances. Help rate!

EDIT: A fix made by Frederick Slickerman fixes one problem but creates another. This time the error:

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

Please carry me and help me solve this problem.

+5
source share
3 answers

++ . . ConditionalInput<int>(...).

+6

row = ConditionalInput<int>(...) 

.

+3

I noticed that you also need to specify the return type first, if it should be explicitly specified as Conditional<int>(...).

template <class T, class A>
T function (A) { ... }

whereas the following will lead to compilation errors:

template <class A, class T>
T function (A) { ... }
0
source

All Articles