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

后端 未结 1 1712
清酒与你
清酒与你 2021-01-25 16:53

After solving this simple issue, I had to ask :

-> In the H file in a class ex a const static member is defined, e.g. :

class ex {
    const static int m         


        
相关标签:
1条回答
  • 2021-01-25 16:56

    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.

    0 讨论(0)
提交回复
热议问题