is this code ok?
void SomeClass :: foo(const char * _name) {
//name is of type const char *
name = std::string(_name).c_str();
}
It's ok since it compiles and doesn't cause undefined behavior.
It's not ok since name points to an invalid memory after the statement completes execution.
name = std::string(_name).c_str();
At the end of this statement the temporary std::string is destroyed and it frees the memory of c_str().
should i do an old school strcpy ?
No, just change name to be std::string:
void SomeClass :: foo(const char * _name) {
//name is of type std::string
name = _name;
}