Jump to content
  • Advertisement
Sign in to follow this  

why use the costom copy string function?

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!