Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why do people seem to prefer to use "m_variable" in Visual C++?  What does the M stand for?

Posted on 2011-02-12
5
Medium Priority
?
480 Views
Last Modified: 2013-12-14
Can someone explain to me why it seems that the preferred way of naming variables is to use "m_" in front?  ie "m_x, m_y, etc.?"

Also, let's say I want to rename the variable from "m_x" to "m_Input1"..how do I do this?  I've created a dialog-based MFC app in VS 2008, and would like to rename a variable that I had earlier attached to a button control.

Thanks.
0
Comment
Question by:shaolinfunk
  • 2
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 34879771
m_
That is just convention to indicate a member variable of a class as oposed to a local variable in a function.

To change the name of a variable, well if you have to do so then use Ctrl h for a search/replace dialog.


ps.  If you are a beginner at coding then I would strongly suggest buying a book (or a few) and reading them.

Programming Windows with MFC, second edition by Jeff Prosise is very good, but it doesn't cover the very latest additions to MFC.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 34879815
Thanks for explaining.  I'm currently working out of Ivor Horton's Beginning VC++ 2008, which is great, but doesn't address questions I have regarding dialog-based MFC apps.

I will check out that Prosise book, thank you!
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 34879829
I would expect that book does have at least a mention of naming conventions.  It helps other coders when they see a piece of code:
m_dStartTemperature = GetTemp();

m_  the variable is global to the class
d the variable is a double
StartTemperature is what the variable should be having as a value

compare with
x = GetTemp();

x is ???, start looking at the previous lines and in the header file...
0
 
LVL 40

Expert Comment

by:evilrix
ID: 34879951
It's called Hungarian Notation.

http://en.wikipedia.org/wiki/Hungarian_notation

0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 34880164
yes andy and evil, the book did go over hungarian notation as it relates to data types.  so an integer might be called nAge or intAge....but i couldn't understand which data type m_ could possibly refer to until you clarified it for me.  thank you!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question