Quote:
Originally posted by Davros
No they're both rubbish! :)
Code 1 assigns to a local variable, which will be lost as soon as the constructor completes.
Code 2 is a horrible way to copy a string and doesn't take into account the null terminator, which would cause you all sorts of problems. However, it isn't a problem, because again the pointer is local and will be lost also, resulting in a memory leak.
What do you want to do? Copy a string at the constructor? Or just hold pointer to an persistent string?
Sorry, obviously I should have declared the char* pointer in the header file as a private member.