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

Copy Constructor or Copy Assignment?

C++ code walkthrough · Question 52
easyClasses

Code

Read carefully. What does this print?
1#include <iostream>
2using namespace std;
3 
4class Tag {
5public:
6 Tag() { cout << "default" << endl; }
7 Tag(const Tag& other) { cout << "copy" << endl; }
8 Tag& operator=(const Tag& other) {
9 cout << "assign" << endl;
10 return *this;
11 }
12};
13 
14int main() {
15 Tag a;
16 Tag b = a;
17 Tag c(a);
18 Tag d;
19 d = a;
20 return 0;
21}

Your answer