CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

Copy or Move: Which Constructor Runs?

C++ code walkthrough · Question 61
easyClasses

Code

Read carefully. What does this print?
1#include <iostream>
2#include <utility>
3using namespace std;
4 
5class Tag {
6public:
7 Tag() { cout << "default" << endl; }
8 Tag(const Tag& other) { cout << "copy" << endl; }
9 Tag(Tag&& other) noexcept { cout << "move" << endl; }
10};
11 
12int 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}

Your answer