← Back to Question List
C++ Code Walkthrough #61
Copy or Move: Which Constructor Runs?
📄 Code
Read carefully — what does this print?1#include <iostream>2#include <utility>3using namespace std;45class Tag {6public:7 Tag() { cout << "default" << endl; }8 Tag(const Tag& other) { cout << "copy" << endl; }9 Tag(Tag&& other) noexcept { cout << "move" << endl; }10};1112int main() {13 Tag a;14 Tag b = a;15 Tag c = std::move(a);16 Tag d(std::move(b));17 Tag e(c);18 return 0;19}