Код: Выделить всё
const int i = 0; //i is top-level const
auto j = i; //j is an int
Код: Выделить всё
const int * ptr = nullptr //ptr is low-level const;
auto ptr2 = ptr; //ptr2 is also const int*
Код: Выделить всё
int var;
const int &ref = var; //ref is low-level const reference
auto ref2 = ref; //ref2 is int! I had this previously as int&, which is wrong`
Проверено на компиляторе C++ VS2017.
Изменить: спасибо за все ответы. !
Таким образом, auto не выводит ссылки https://www.learncpp.com/cpp-tutorial/t ... and-const/
Подробнее здесь: https://stackoverflow.com/questions/784 ... ot-deduced
Мобильная версия