Normally, variable names don't even exist in the compiled EXE file. The machine code just keeps track of the variable's address in memory, it doesn't need a name. (If you use a de-compiler, it will make-up it's own variable names.)

I've never tried using <typeinfo>, but it might work for you. I think it can give you an object name, but I have no idea if it also keeps track of variable names.

Well the reason I wanted to do something like this is because I am designing a matrix class and when I do something like

Code:

Matrix jacobian;
...
cout << jacobian;

I want it to print out

jacobian = [.....]

This is similar to what Matlab does. Obviously I could include a string within the class and make the developer explain what the matrix represents, but I figured if something like this was indeed possible it would encourage the developer to use descriptive variable names.

>This is similar to what Matlab does.
Matlab is much higher level than C++. If you want a scripting language, use one or write an interpreter for some pseudo-C++. If you want C++, you have to realize that compile-time symbols are generally going to be lost during compilation. The only way to retain them is to store them separately at runtime with your own machinery.

Now, what is the "name" of var1 inside func1:
- when it's called with someVariable?
- when it's been called from func2 with a pointer indexed?

Having "meaningfull" variable names is about style, and a goor programmer/sw engineer will use good style - what the definition of good style is of course also slightly depending on several factors, and what one person thinks is a good name isn't necessarily what everyone else thinks is a good name.

--
Mats

Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.