Cpp

From Y Wiki

Move

// Online C++ compiler to run C++ program online
#include <iostream>
#include <optional>
using namespace std;


class A 
{
public:
    A() { cout << "A's constructor: " << this << endl; }
    A(const A& a) { cout << "A's copy constructor: " <<this << " form " << &a << endl; }
    A(A&& a) { cout << "A's move constructor: " <<this << " form " << &a   << endl; }
    A& operator=(const A& a) { cout << "A's assignment" <<this << " form " << &a  << endl; }
    ~A() { cout << "A's destructor: "<< this << endl; }
};


void f(A&& q) {}

int main() 
{
    A d1;  
    f(std::move(d1));
    return 0;
}