samedi 29 août 2015

decltype definning a variable as a reference

I was studying about the differences between auto and decltype type specifier and I had saw in another question that when I use decltype with a reference, like this:

const int ci = 0, &cj = ci;
decltype(ci) x = 0;
decltype(cj) y = x; 

decltype(cj) will not give me the type of the object that cj refers to (that is, const int) but will give me the type of cj itself. So y will be const int&.

Why it happens? And it could affect my code in someway? Is it related with the difference between decltype() and decltype(())?

Aucun commentaire:

Enregistrer un commentaire