Hi. I've seen people naming their variables as m_*. What does the m_ mean? And why do you use it?
Hi. I've seen people naming their variables as m_*. What does the m_ mean? And why do you use it?
It usually indicates that this is a (class) member variable.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
As explained, m_ (or m) means "member" variable for classes, assuming it actually means anything.
There are MANY ways to name variables, and the "where does this belong" naming convention is just one of those. It does make sense to indicate that a variable is part of a class, to differentiate it from for example function parameters or local variables in the function.
Where I work, arguments to functions are prefixed with a, so you can tell the difference between an argument and other local variables too.
Many people also prefix globals with g or g_.
Other naming conventions indicate what the type of a variable is, and I've seen prefixing of the type "ui32" to indicate that it's a "unsigned integer" that is 32 bits long. I don't find that particularly helpful most of the time (especially when you have an editor that allows you to jump to the declaration/definition of a variable easily), but I can see the logic.
Whether you use a prefix naming convention or not, make sure that you follow a consistent system - there's nothing worse than looking at code that has three different naming conventions in the same project. You never really know what you are looking at...
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
It is nOthing, JUst a Microsoft Naming Convention..
m_ = Member variable of class,
_ = Public variable of class ...
So on....
I do this:
As pointed out, it is all preference rather than essentials. But like matsp said, be consistant.Code:class Foo { private: int m_data; // data member of a class int *pm_data; // data member of a class that is also a pointer };
Double Helix STL