What does `m_` variable prefix mean?

前端 未结 9 732
太阳男子
太阳男子 2020-12-22 18:47

I often see m_ prefix used for variables (m_World,m_Sprites,...) in tutorials, examples and other code mainly related

9条回答
  •  离开以前
    2020-12-22 19:23

    As stated in many other responses, m_ is a prefix that denotes member variables. It is/was commonly used in the C++ world and propagated to other languages too, including Java.

    In a modern IDE it is completely redundant as the syntax highlighting makes it evident which variables are local and which ones are members. However, by the time syntax highlighting appeared in the late 90s, the convention had been around for many years and was firmly set (at least in the C++ world).

    I do not know which tutorials you are referring to, but I will guess that they are using the convention due to one of two factors:

    • They are C++ tutorials, written by people used to the m_ convention, and/or...
    • They write code in plain (monospaced) text, without syntax highlighting, so the m_ convention is useful to make the examples clearer.

提交回复
热议问题