Why use prefixes on member variables in C++ classes

前端 未结 29 1405
半阙折子戏
半阙折子戏 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条回答
  •  忘掉有多难
    2020-11-28 17:51

    I almost never use prefixes in front of my variable names. If you're using a decent enough IDE you should be able to refactor and find references easily. I use very clear names and am not afraid of having long variable names. I've never had trouble with scope either with this philosophy.

    The only time I use a prefix would be on the signature line. I'll prefix parameters to a method with _ so I can program defensively around them.

提交回复
热议问题