jeudi 5 novembre 2020

Compilation error in auto keyword in C++11

I know that the use of auto keyword can automatically deduce the type of the variable from the Rvalue. Then why does the following function snippet in my code have a compilation error?

auto getName(auto str = "John Doe") {
    return str;
}

The compilation error is 'auto' not allowed in function prototype. I googled a bit and I think auto can not be used in the function prototypes. Why So?

Aucun commentaire:

Enregistrer un commentaire