Is it a good idea to return " const char * " from a function?
Posted
by AJ
on Stack Overflow
See other posts from Stack Overflow
or by AJ
Published on 2010-03-25T10:06:44Z
Indexed on
2010/03/25
10:13 UTC
Read the original article
Hit count: 274
Now I have a function that has to return a string. I saw a particular implementation where he returns a const char * from the function.
Something like this:
const char * GetSomeString()
{
........
return somestlstring.c_str();
}
SomeOtherFoo ()
{
const char * tmp = GetSomeString();
string s = tmp;
}
Now I felt there is something potentially wrong with this. Is my gut feel right? or Is this a perfectly safe code?
Kindly give me ur suggestions. I have a feeling return const char * this way might result in havoc..
Thanks, Arjun
© Stack Overflow or respective owner