对于同一个类型有两个const
会引发警告/错误。但是如果该类型已经使用typedef
定义,则编译器会接受它(Visual Studio 2013和在线编译器C++ shell都是如此)。
#include <iostream>
typedef const int value_type;
int main()
{
const value_type n = 0; //ok
const const int n2 = 0; //error C4114
return 0;
}
有人知道为什么吗?是因为一个是const(const int)
,和const const int
不同吗?