vendredi 1 février 2019

Why is `const T&` not sure to be const?

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