tags:

views:

46

answers:

2
+1  A: 
template <typename T> 
void f(const typename C<T>::type& c) { }

This is allowed, but a qualified type is one of the non-deduced contexts. That is, template argument deduction won't work for this, so you'll have to call the function like so:

f(42);      // won't work
f<int>(42); // works

If you don't want to supply the type argument explicitly, one option is to have the function just take a T:

template <typename T> void f(const typename T& c) { }
James McNellis
commernie
Oops, I now realize this is exactly what you said would work. Thanks again.
commernie
@commernie: No, I had it backwards; I think I must have corrected it just before you posted your comment. Sorry about that and glad to have helped.
James McNellis
A: 

I got your same error using:

template <typename T>
void f(typename const C<T>::type& c) {}

but got no error using

template <typename T>
void f(const typename C<T>::type& c) {}
rlduffy
Yep. When I tried that before I got a different error (on another line) which was very similar to this one, and this confused me into thinking that did not work. All's good now. Thanks!
commernie