Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I generally don't use a prefix for member variables.</p> <p>I used to use a <code>m</code> prefix, until someone pointed out that "C++ already has a standard prefix for member access: <code>this-&gt;</code>.</p> <p>So that's what I use now. That is, <em>when there is ambiguity</em>, I add the <code>this-&gt;</code> prefix, but usually, no ambiguity exists, and I can just refer directly to the variable name.</p> <p>To me, that's the best of both worlds. I have a prefix I can use when I need it, and I'm free to leave it out whenever possible.</p> <p>Of course, the obvious counter to this is "yes, but then you can't see at a glance whether a variable is a class member or not".</p> <p>To which I say "so what? If you need to know that, your class probably has too much state. Or the function is too big and complicated".</p> <p>In practice, I've found that this works extremely well. As an added bonus it allows me to promote a local variable to a class member (or the other way around) easily, without having to rename it.</p> <p>And best of all, it is consistent! I don't have to do anything special or remember any conventions to maintain consistency. </p> <hr> <p>By the way, you <em>shouldn't</em> use leading underscores for your class members. You get uncomfortably close to names that are reserved by the implementation.</p> <p>The standard reserves all names starting with double underscore or underscore followed by capital letter. It also reserves all names starting with a single underscore <em>in the global namespace</em>.</p> <p>So a class member with a leading underscore followed by a lower-case letter is legal, but sooner or late you're going to do the same to an identifier starting with upper-case, or otherwise break one of the above rules.</p> <p>So it's easier to just avoid leading underscores. Use a postfix underscore, or a <code>m_</code> or just <code>m</code> prefix if you want to encode scope in the variable name.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload