r*******y 发帖数: 1081 | 1 template void f(vector::iterator){}
this can not compile because of vector::iterator in the parameter
list. Why this parameter is not allowed here? Thanks. |
t****t 发帖数: 6806 | 2 template void f(typename vector::iterator) {}
【在 r*******y 的大作中提到】 : template void f(vector::iterator){} : this can not compile because of vector::iterator in the parameter : list. Why this parameter is not allowed here? Thanks.
|
r*******y 发帖数: 1081 | 3 cool
we have to tell the compiler that vector::iterator is a typename
Thanks.
【在 t****t 的大作中提到】 : template void f(typename vector::iterator) {}
|
l*********s 发帖数: 5409 | 4 why the compiler cannot deduce it is a typename by itself? What is the
ambiguity there?
【在 r*******y 的大作中提到】 : cool : we have to tell the compiler that vector::iterator is a typename : Thanks.
|
t****t 发帖数: 6806 | 5 given type T, compiler can deduce. but when T is unknown, it can not.
【在 l*********s 的大作中提到】 : why the compiler cannot deduce it is a typename by itself? What is the : ambiguity there?
|
l*********s 发帖数: 5409 | 6 Got it, thank you!
【在 t****t 的大作中提到】 : given type T, compiler can deduce. but when T is unknown, it can not.
|
S*******s 发帖数: 13043 | 7 with typename, it can.
without typename, it won't be taken as something else.
so, why typename here is a must? should they better make the typemane here
optional?
【在 t****t 的大作中提到】 : given type T, compiler can deduce. but when T is unknown, it can not.
|
t****t 发帖数: 6806 | 8 without keyword typename, by default it is member variable. if it is not
member variable, it is ill-formed.
【在 S*******s 的大作中提到】 : with typename, it can. : without typename, it won't be taken as something else. : so, why typename here is a must? should they better make the typemane here : optional?
|