I am getting an invalid pointer error when I call the below function. Why is this happening?
void Get(const char* value)
{
string st(\"testing string\");
val
variable inside Get()
gets destroyed once Get()
returns, thus the pointer to val
body becomes invalid. Also value
parameter is a copy of the original pointer, so the original val
pointer in main()
function is left unchanged and still holds a null pointer value.
Change it to
string Get()
{
string st("testing string");
string val = st.substr(1, st.length());
return val;
}