How do I specialize a nested template? (See error below.)
using std::reverse_iterator;
template<typename It>
reverse_iterator<It> make_reverse_iterator(const It &it)
{
return reverse_iterator<It>(it);
}
template<typename It>
It make_reverse_iterator<reverse_iterator<It> >(const reverse_iterator<It> &it)
{
// Above ^
// error C2768:
// 'make_reverse_iterator': illegal use of explicit template arguments
return it.base();
}
This is a partial specialization of a function template. This is not allowed.
You can solve the problem in this example with an overload instead:
template<typename It>
It make_reverse_iterator(const reverse_iterator<It> &it)
{
return it.base();
}
In cases where overloads don't work you can resort to partial specialization of class templates.
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