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
468 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

757 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

17 Experts available now in Live!

Get 1:1 Help Now