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
470 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 44

Accepted Solution

by:
AndyAinscow earned 500 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 44

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now