Class members prefixed with underscore (

This question already has an answer here:

  • What are the rules about using an underscore in a C++ identifier? 5 answers

  • From the C++03 standard: §17.4.3.1.2/1

    Certain sets of names and function signatures are always reserved to the implementation:

  • Each name that contains a double underscore ( __ ) or begins with an underscore followed by an upper-case letter (2.11) is reserved to the implementation for any use.

  • Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

  • The equivalent text is present in C++11 §17.6.4.3.2/1


    Personally, I use m_name , with 'm' standing for 'member'.

    By the way, I also use p_ for parameters in my functions and g_ for the few unavoidable globals.

    (then I usually get bashed by SO users because it looks like Hungarian notation ;-) But it is not.)


    Please also look here: What are the rules about using an underscore in a C++ identifier?

    I've seen a lot of code using single underscores as a prefix or double underscores in an indentifier and it simply worked. But you never know. The identifiers are reserved and anything may happen, depending on the compiler.

    链接地址: http://www.djcxy.com/p/40316.html

    上一篇: 3 ='c'在C和C ++中有效吗?

    下一篇: 带有下划线前缀的类成员(