jeudi 15 octobre 2020

C++ template parameter specify the second

this is my code:

template <typename T, int index>
int echo(T t) {
    return index - 1;
}
echo<3>(1); // error: invalid template argument for 'T', type expected

I think that the compiler is fully capable to deduce T. How can I do to use echo when T is the first template parameter except below:

echo<decltype(x), 3>(x);

Aucun commentaire:

Enregistrer un commentaire