This question already has an answer here:
Following does not resolve and gives compiler error as expected:
void foo (int&&); // error: cannot bind ‘int’ lvalue to ‘int&&’
int i;
foo(i);
However, following resolves and gives no error:
template<typename T> void foo (T&&); // OK!!!
int i;
foo(i);
Question: How is lvalue binding to rvalue template possible?
Extra: Is there any way to enforce compiler error in case of templates?
[Note:
- In both the cases, if there is any lvalue overload then that is resolving.
- Using linux's
abifunction, printing the type ofigivesint]
Aucun commentaire:
Enregistrer un commentaire