Here are some sample code.
a. int ii = 0;
b. const int ci = ii;
c. auto e = &ci; --> e is const int *
d. auto &f = 42; --> invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
e. const auto &g = 42 --> ok
Observation:
1. for item c) the type const is automatically determined 2. for item d) the type of const is not automatically determined 3. for the sentence e) the type of const must be added manually in order for it to work.
Why is type const automatically output for clause c but not d?
source
share