المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Function out of scope



C++ Programming
09-08-2009, 03:13 PM
Hi,

In the below code ret value become invalid as it comes out of the funcation scope. can any suggest better idea to solve this.

CString ToStr()
{
CString ret = "test";
return ret;
}

void fun()
{
CString val = ToStr(); // it returns nothing (bad pointer)
}

I have compiled this code in MS VC++2005 under winxp OS.

Thanks,
Nandu