This question already has an answer here:
Consider:
int main()
{
int * i0 = new int;
*i0 = 666; // OK
const int * i1 = new int;
*i1 = 666; // FAIL due to const
auto i2 = new int;
*i2 = 666; // OK
const auto i3 = new int;
*i3 = 666; // OK, WHY?
const auto * i4 = new int;
*i4 = 666; // FAIL due to const
return 0;
}
Why does case i3 work? I have always thought that in this case const auto
would be implicitly const int *
but I guess this is not the case?
Aucun commentaire:
Enregistrer un commentaire