why use the costom copy string function?
void CopyString(const char* input, char** output)
{
if( input )
{
UINT length = (UINT)::strlen(input) + 1; // add 1 for terminating null charater.
*output = new char[length];
::strcpy(*output, input);
}
else
{
*output = 0;
}
}
the stdio.h : strcpy() is not good or not work?
The code you have is a function that wraps strcpy(). The difference is that the wrapper function automatically allocates memory for the new string, while a direct call to strcpy() needs to have the memory allocated for it.
Copy constructor is also used alot for your own classes, it prevents a shallow copy such that when Object1 is copied by Object2 they aren't pointing to the same data in memory so that if Object1 were deleted, attempting to use Object2 results in a runtime error I think?
Goodluck
Goodluck
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement