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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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 clear a vector as well as how to detect empty vectors in C++.

786 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