← Back to Question List
C++ Code Walkthrough #3
Constructor and Destructor Order
📄 Code
Read carefully — what does this print?1#include <iostream>2using namespace std;34class Box {5public:6 int id;7 Box(int i) : id(i) {8 cout << "Create " << id << endl;9 }10 ~Box() {11 cout << "Destroy " << id << endl;12 }13};1415int main() {16 Box a(1);17 Box b(2);18 return 0;19}