3 ms·
Shallow copy is the general concept. Move semantics is a special case where the unique ownership is enforced. Here is simple example of the idea: Widget::Wid
by namirez 7y ago
Shallow copy is the general concept. Move semantics is a special case where the unique ownership is enforced. Here is simple example of the idea:
Widget::Widget(Widget&& w) {
this->ptr = w.ptr; // shallow copy
w.ptr = nullptr; // nullify the source
}
- clappski 7y agoYou could use; auto* p2 = std::exchange( p1, nullptr );