Z
ZMZ
I tried to search google but couldn't find anything useful. Everybody
is talking about the rule, but nobody can tell why.
From C++ Standard 2003, 8.3.2/1
Cv-qualified references are ill-formed except when the cv-qualifiers
are introduced through the use of a typedef (7.1.3) or of a template
type argument (14.3), in which case the cv-qualifiers are ignored.
Meaning that,
int b;
int &const a = b; //ill-formed
typedef int &RefType;
const RefType c = b; //ok, but const ignored
I am very curious about the reason behind such rule. Since reference
cannot be re-binded later on, which means that a reference is already
a "const" value, I can't see any harm to add const-qualifier to a
reference. What's the reason to ban such cv-qualified reference?
On the other hand, why cv-qualified reference via typedef or template
are allowed?
Thanks in advance.
is talking about the rule, but nobody can tell why.
From C++ Standard 2003, 8.3.2/1
Cv-qualified references are ill-formed except when the cv-qualifiers
are introduced through the use of a typedef (7.1.3) or of a template
type argument (14.3), in which case the cv-qualifiers are ignored.
Meaning that,
int b;
int &const a = b; //ill-formed
typedef int &RefType;
const RefType c = b; //ok, but const ignored
I am very curious about the reason behind such rule. Since reference
cannot be re-binded later on, which means that a reference is already
a "const" value, I can't see any harm to add const-qualifier to a
reference. What's the reason to ban such cv-qualified reference?
On the other hand, why cv-qualified reference via typedef or template
are allowed?
Thanks in advance.