It will store a dangling pointer that you must not access. It may contain the string "something"
or it may not. It doesn't matter, because accessing it is undefined behaviour, and should be avoided completely.
If you want to copy the string do this:
c = strdup( c.c_str() );
And don't forget to free(c)
in ~Class1()
Beware that if you call func1
twice, you will leak memory. You probably want to initialise c
to NULL
in the constructor, and call free(c)
before reassigning it in func1
.
Surely a better approach is to store a std::string
instead of a char*
, which manages memory properly for you.