KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I created two simple functions which get template parameters and an empty struct defining a type: //S<T>::type results in T& template <class T> struct S { typedef typename T& type; }; //Example 1: get one parameter by reference and return it by value template <class A> A temp(typename S<A>::type a1) { return a1; } //Example 2: get two parameters by reference, perform the sum and return it template <class A, class B> B temp2(typename S<A>::type a1, B a2)//typename struct S<B>::type a2) { return a1 + a2; } The argument type is applied to the struct S to get the reference. I call them with some integer values but the compiler is unable to deduce the arguments: int main() { char c=6; int d=7; int res = temp(c); int res2 = temp2(d,7); } Error 1 error C2783: 'A temp(S::type)' : could not deduce template argument for 'A' Error 2 error C2783: 'B temp2(S::type,B)' : could not deduce template argument for 'A' Why is this happening? Is it that hard to see that the template arguments are char and int values?
Tags (comma-separated)
Save Edits
Cancel