how can you send the name of a variable as a parameter?

I'm experimenting writing functions which use new and delete on passed pointers, but the function which allocates writes to a text file which file and line the memory was allocated on, and the name of the variable, and the function which deallocates needs to search for the variable name in the text file and then when it finds it, erase the line.

This will make memory leak detection easy as at the end of a program you will have a text file containing the name, file and line of every piece of memory which was not freed. To do this though I will need to pass a the name of the variable into the function, I can't think of a way to do this.

Danke.
Maybe like this?
1
2
3
4
5
6
7
8
9
10
11
void SomeFunc(int some val, char anotherval, string OptDebug = "")
{
	if(OptDebug == "")
	{
		//run code normally
	}
	else
	{
		//run code with debugging output, using OptDebug to pass the variable names, ect
	}
}
Although it doesn't appear in the standard, the preprocessor often provides __FILE__ and __LINE__ that give the file name and line number of a line in a file. These are often used for exactly what you might need them for.

There isn't a standard way of determining the function name.
Topic archived. No new replies allowed.