samedi 31 mai 2014

Error when trailing return type is replaced by automatic return type


Vote count:

0




I was recently wondering about the rules of applicability of automatic return types (which was marked as a duplicate of a question about the syntax of functions with automatic return types).


It seems that wherever uniformly deducable, the return type can be used by automatic return type functions. Yet while trying to get advantage of this feature, a working snippet that looked like this :



#include <iostream>
using namespace std;

auto f(int *i) -> decltype(i[0]) {
return i[0];
}

int main() {
int ar[] = {1, 2, 4, 5, 6, };
f(ar) = 4;
cout << ar[0];
return 0;
}


turned non-compilable due to automatic return type :



auto f(int *i) {
return i[0];
}


What is the problem here?



asked 39 secs ago






Aucun commentaire:

Enregistrer un commentaire