Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Default functions implemented by compiler
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Frederick Gotham, post: 2565842"] Murali Krishna posted: Pre-requisites: (1) An original object which to copy. (2) A suitably aligned memory buffer. #include <string> int main() { std::string original; unsigned char *p_buf = new unsigned char[sizeof(std::string)]; /* Copying goes here */ /* Time for clean-up */ delete [] p_buf; } Here's a shallow copy: #include <string> #include <cstring> int main() { std::string original; unsigned char *p_buf = new unsigned char[sizeof(std::string)]; /* Copying goes here */ std::memcpy(p_buf, &original, sizeof original); /* Time for clean-up */ delete [] p_buf; } And here's a deep copy: #include <string> int main() { std::string original; unsigned char *p_buf = new unsigned char[sizeof(std::string)]; /* Copying goes here */ new(p_buf) std::string(original); /* Time for clean-up */ typedef std::string string; reinterpret_cast<std::string*>(p_buf)->~string(); delete [] p_buf; } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Default functions implemented by compiler
Top