Original Post
I am getting the warning "warning C4172: returning address of local variable or temporary" in a few of my functions that returns a char*. Here is the code in a function that I get the error. It returns the selected item in the listbox. I know lots of people don't like char's and put so much emphasis on strings, but I would like to add functions to handle both strings and char's. I could change char Text[256] to char* Text = new char[256] and it works fine, but then I have a new pointer that I would need to delete every time I run the function. Is there a way to change the code I am using to fix this? I know I could change all the functions I use this type of code in and put an extra parameter to accept a variable to put the text into and not return anything, or I could probably create a new char and lstrcpy it into a char array and delete it, but it might cause the same error, I am not sure how to go about fixing it the best way. Thanks in advance. [Edited by - GetWindowRect on September 9, 2005 9:29:04 PM]
char Text[256];
SendMessage(m_hWnd, LB_GETTEXT, (WPARAM)SelectedIndex(), (LPARAM)&Text);
return Text;