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 0 to int *, Since when you pass first argument as int *, object_t is int * and the compiler expects an int * as the third argument as well. It tells you that 0 is an invalid type as the third argument for the class template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With