有两个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
不同?
此代码是确定的,你准确的问题是什么? –