For example, I have a constructor like
myClass(const char* name);
Can it be like
myClass(const char* name);
{
someInnerField = name;
}
or I should copy input string to inner field by value?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What’s safe is:
Your version could fail if the class destroys the memory its member points to (and you still use it outside the scope of the class) or if the memory is destroyed outside the class (and you continue to use it inside).