Cpp

From Y Wiki
Revision as of 11:55, 28 August 2024 by Yba (talk | contribs) (Created page with "== Move == <syntaxhighlight lang="c++"> // 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 << " for...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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;
}