typedef int& A can't be used as const A a = 1;

Viewed 53

why can't it declare as

typedef int& A;
const A a = 3;

which throws cannot bind non-const lvalue reference of type 'A' {aka 'int&'} to an rvalue of type 'int'

Does it have any difference between const int& a = 3;

1 Answers

Does it have any difference between const int& a = 3;

Yes. Given const A, const is qualified on A itself; A is a reference as int &, and the reference itself can't be const-qualified, the const qualifier is just ignored. As the effect, const A is same as int& (but not const int&), and int& a = 3; is ill-formed as the error message said.

Related