Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace std {
- class string
- {
- private:
- char *_M_string;
- size_t _M_size;
- // as you can see, std::string is basically just a wrapper
- // around char * and size
- public:
- // this constructs an empty string
- string()
- : _M_string(nullptr), _M_size(0) { }
- // this will actually copy the string, so it's not interesting to us...
- string(const string &other);
- // this is the constructor that will be called when you use std::move
- string(string &&other)
- : string() // <-- construct an empty string first
- {
- swap(_M_string, other._M_string);
- swap(_M_size, other._M_size);
- // and now "other" string is empty and "this" string has its content
- }
- ~string()
- {
- // deleting a nullptr is fine
- delete [] _M_string;
- }
- //... other stuff
- };
- } // std
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement