#include #include #include class MyType { public: MyType() { pointer_ = new int; *pointer_ = 1; memset(array_, 0, sizeof(array_)); vector_.push_back(3.14); } MyType(MyType&& other) { fprintf(stderr, "move ctor\n"); // Steal the memory, null out |other|. pointer_ = other.pointer_; other.pointer_ = nullptr; // Copy the contents of the array. memcpy(array_, other.array_, sizeof(array_)); // Swap with our (empty) vector. vector_.swap(other.vector_); } ~MyType() { delete pointer_; } private: int* pointer_; char array_[42]; std::vector vector_; }; void ProcessMyType(MyType type) { } MyType MakeMyType(int a) { if (a % 2) { MyType type; return type; } MyType type; return type; } int main(int argc, char **argv) { // MakeMyType returns an rvalue MyType. // Both lines below call our move constructor. MyType type = MakeMyType(2); ProcessMyType(MakeMyType(2)); }