For the following code, the compiler complaints that no known conversion from 'const char *' to 'int' for 1st argument
. Compiler should know that t
is an int
while calling g
. Therefore for f("a")
, g
won't be called.
Is there a good way to handle this without template overloading?
void g(int i) {
cout << i << endl;
}
template <typename T>
void f(T t) {
if (is_same<T, int>::value) {
g(t);
}
}
int main() {
f("a");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire