Why use prefixes on member variables in C++ classes

前端 未结 29 1407
半阙折子戏
半阙折子戏 2020-11-28 17:39

A lot of C++ code uses syntactical conventions for marking up member variables. Common examples include

  • m_memberName for public members (where public
29条回答
  •  旧时难觅i
    2020-11-28 17:50

    You have to be careful with using a leading underscore. A leading underscore before a capital letter in a word is reserved. For example:

    _Foo

    _L

    are all reserved words while

    _foo

    _l

    are not. There are other situations where leading underscores before lowercase letters are not allowed. In my specific case, I found the _L happened to be reserved by Visual C++ 2005 and the clash created some unexpected results.

    I am on the fence about how useful it is to mark up local variables.

    Here is a link about which identifiers are reserved: What are the rules about using an underscore in a C++ identifier?

提交回复
热议问题