【发布时间】:2012-07-18 04:03:28
【问题描述】:
以下给出了预期的错误:
int* const const p = new int; // g++ error: duplicate cv-qualifier
但下面没有给出任何错误,即使它相当于上面的一个:
typedef int* const intp_const;
intp_const const p = new int; // ok !
// ^^^^^ duplicate ?
为什么编译器会忽略多余的 const ?
[注意:intp_const const与const char* const不同,因为*p = <value>;是可能的。]
【问题讨论】:
-
"为什么编译器会忽略多余的 const ?" 为什么不呢?
-
@curiousguy,因为没有
typedef,额外的const不会被忽略(第一行)。 -
所以问题是:“为什么额外的
const是第一行的错误?”
标签: c++ pointers constants language-lawyer