← Back to Question List
C++ Code Walkthrough #52
Copy Constructor or Copy Assignment?
📄 Code
Read carefully — what does this print?1#include <iostream>2using namespace std;34class 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};1314int main() {15 Tag a;16 Tag b = a;17 Tag c(a);18 Tag d;19 d = a;20 return 0;21}