vendredi 1 septembre 2017

how do I passing template parameter correctly?

The following code doesn't compile because T is now deduced to be a reference, (either l-value or r-value, but this is not relevant here). So std::vector can't take T as an argument anymore. Does anyone know some way to fix this? Thanks!

template<typename T>
void func( T&& t )
{
    std::vector<T> v;
}

Answer: use std::decay as commented.

Aucun commentaire:

Enregistrer un commentaire