示例代码片段
const const const int x = 10;
int main()
{}
在 C 中编译,但在 C++ 中不编译。为什么要用 C 编译?我认为这在 C 中也会失败。没关系。
C++ 标准的哪一部分禁止使用重复的const
,C 标准的哪一部分允许这样做?
最佳答案
C99 §6.7.3/4:
If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedef s, the behavior is the same as if it appeared only once.
是的,这是有效的 C99,您的发现是正确的。
关于c++ - 在 C 中允许重复的 const 限定符但在 C++ 中不允许?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58634707/