Bjarne 解释了为什么 const 可以放在类型之前或之后。
http://www.stroustrup.com/bs_faq2.html#constplacement
"const T" and "T const" were - and are - (both) allowed and equivalent. [...]
为什么?当我发明“const”(最初命名为“readonly”并有一个相应的“writeonly”)时,我允许它在类型之前或之后出现,因为我可以这样做而不会产生歧义。
我的直接想法是,“好吧,这是有道理的,但如果这就是原因,那么为什么 const 是特殊的?” 显然不是。clang 和 gcc 都不会发出以下警告。
int volatile myint;
int static myotherint;
这是有道理的,但我从未见过这种语法被使用过,甚至没有被提及过。是否在类型有效的 C++ 之后放置 static 和 volatile 限定符?
如何从标准的文本中确定这一点?