auto reference in c++11

2019-02-25 04:12发布

问题:

I have some trouble about auto reference.

const int i = 1;
auto & ri1 = i; 
auto & ri2 = 1; //error

Why is deduced type of ri1 const int but not ri2?

Thanks!

回答1:

Since i has type const int, but 1 has type int.