#include <iostream>
#include <string>
#include <utility> // For std::move
class MyClass {
public:
std::string data;
// Constructor
MyClass(const std::string& str) : data(str) {
std::cout << "Constructed\n";
}
// Move Constructor
MyClass(MyClass&& other) noexcept : data(std::move(other.data)) {
std::cout << "Move Constructed\n";
}
};
int main() {
MyClass obj1("Hello, World!");
//GE std::cout << "obj1.data: " << obj1.data << std::endl; // data is present
MyClass obj2(std::move(obj1)); // 'std::move(obj1)' produces an xvalue
std::cout << "obj2.data: " << obj2.data << std::endl;
//GE std::cout << "obj1.data: " << obj1.data << std::endl; // data is gone
return 0;
}