Why use prefixes on member variables in C++ classes

前端 未结 29 1389
半阙折子戏
半阙折子戏 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:54

    Others try to enforce using this->member whenever a member variable is used

    That is usually because there is no prefix. The compiler needs enough information to resolve the variable in question, be it a unique name because of the prefix, or via the this keyword.

    So, yes, I think prefixes are still useful. I, for one, would prefer to type '_' to access a member rather than 'this->'.

提交回复
热议问题