template<typename T>
void f(T a, const T& b)
{
++a; // ok
++b; // also ok!
}
template<typename T>
void g(T n)
{
f<T>(n, n);
}
int main()
{
int n{};
g<int&>(n);
}
Please note: b is of const T& and ++b is ok!
Why is const T& not sure to be const?
Aucun commentaire:
Enregistrer un commentaire