I am trying to implement a template
template <class object_t, long size, object_t nullObject>
class lf_deque
{
// ...
}
when I try to instantiate this template with an int, it compiles fine, but if I try to instantiate with a pointer i get the error:
could not convert template argument '0' to 'int*'
lf_deque<int, 10, 0> intDeque; // WORKS
lf_deque<int*, 10, 0> ptrDeque; // ERROR
any thoughts or ideas why i would get this inconsistency?
In templates when a function/class is resolved with
ADL(Argument Dependent Lookup)Function Template Argument Deduction, there is no implicit conversion. Only exactly matching paramters can resolve to instantiate a appropriate template function/class. That is the root cause of the error.The compiler tells you that it cannot implicitly convert last parameter
0toint *, Since when you pass first argument asint *,object_tisint *and the compiler expects anint *as the third argument as well. It tells you that0is an invalid type as the third argument for the class template.