Why does one have to repeat the const specifier at definition time, if declaration as const is done somewhere else?

落爺英雄遲暮 提交于 2019-12-02 06:12:52

This is a historical thing.

Since C, static on a definition means "internal linkage". When C++ came along, and classes were added to it, Bjarne needed a keyword to signify static members. Not wanting to add new keywords (a preference that largely exists still to this day), he re-used static instead.

Now static meant two different things depending on where you put it. So you can't write static here because it would mean something else. Thus, the language doesn't require you to, as that would be silly.

Beyond that reasoning, it just is. When you create a language, you balance simplicity of specification against simplicity of implementation against simplicity of use, and you come up with a set of rules that are the language. At some point you have to stop quibbling over "why" some insignificant rule was created and just get on with writing your program.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!