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
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

623 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